var egret = window.egret;var __reflect = (this && this.__reflect) || function (p, c, t) {
    p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = this && this.__extends || function __extends(t, e) { 
 function r() { 
 this.constructor = t;
}
for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
r.prototype = e.prototype, t.prototype = new r();
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [0, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var TextField = (function (_super) {
    __extends(TextField, _super);
    function TextField() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return TextField;
}(egret.TextField));
__reflect(TextField.prototype, "TextField");
;
var Sprite = (function (_super) {
    __extends(Sprite, _super);
    function Sprite() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Sprite;
}(egret.Sprite));
__reflect(Sprite.prototype, "Sprite");
;
var Shape = (function (_super) {
    __extends(Shape, _super);
    function Shape() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Shape;
}(egret.Shape));
__reflect(Shape.prototype, "Shape");
;
var DisplayObject = (function (_super) {
    __extends(DisplayObject, _super);
    function DisplayObject() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return DisplayObject;
}(egret.DisplayObject));
__reflect(DisplayObject.prototype, "DisplayObject");
;
var DisplayObjectContainer = (function (_super) {
    __extends(DisplayObjectContainer, _super);
    function DisplayObjectContainer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return DisplayObjectContainer;
}(egret.DisplayObjectContainer));
__reflect(DisplayObjectContainer.prototype, "DisplayObjectContainer");
;
var Point = (function (_super) {
    __extends(Point, _super);
    function Point() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Point;
}(egret.Point));
__reflect(Point.prototype, "Point");
;
var Rectangle = (function (_super) {
    __extends(Rectangle, _super);
    function Rectangle() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Rectangle;
}(egret.Rectangle));
__reflect(Rectangle.prototype, "Rectangle");
;
var Bitmap = (function (_super) {
    __extends(Bitmap, _super);
    function Bitmap() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Bitmap;
}(egret.Bitmap));
__reflect(Bitmap.prototype, "Bitmap");
;
var BitmapData = (function (_super) {
    __extends(BitmapData, _super);
    function BitmapData() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return BitmapData;
}(egret.BitmapData));
__reflect(BitmapData.prototype, "BitmapData");
;
var Stage = (function (_super) {
    __extends(Stage, _super);
    function Stage() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Stage;
}(egret.Stage));
__reflect(Stage.prototype, "Stage");
;
var Tween = (function (_super) {
    __extends(Tween, _super);
    function Tween() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Tween;
}(egret.Tween));
__reflect(Tween.prototype, "Tween");
;
var Ease = (function (_super) {
    __extends(Ease, _super);
    function Ease() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Ease;
}(egret.Ease));
__reflect(Ease.prototype, "Ease");
;
//----------------------------------------------
//以下几种方法在使用前都必须先调用各自的初始化函数
//moon.TipsManager.getIns().init(this.stage);
//moon.LogManager.getIns().init(this.stage);
//moon.AlertManager.getIns().init(this.stage);
var trace = function () {
    var arg = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        arg[_i] = arguments[_i];
    }
    var str = "";
    for (var i = 0; i < arg.length; i++) {
        str += arg[i] + ",";
    }
    str = str.substr(0, str.length - 1);
    moon.LogManager.getIns().logMessage(str);
};
var traceSimple = function () {
    var arg = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        arg[_i] = arguments[_i];
    }
    var str = "";
    for (var i = 0; i < arg.length; i++) {
        str += arg[i] + ",";
    }
    str = str.substr(0, str.length - 1);
    moon.LogManager.getIns().log(str);
};
var alertAuto = function (title, closeTime) {
    if (title === void 0) { title = "提示或警告"; }
    if (closeTime === void 0) { closeTime = 3; }
    moon.AlertManager.getIns().alertAuto(title, closeTime);
};
var alertHand = function (title) {
    if (title === void 0) { title = "提示或警告"; }
    moon.AlertManager.getIns().alert(title);
};
var alertRoll = function (title, bgWidth) {
    if (title === void 0) { title = "提示或警告"; }
    if (bgWidth === void 0) { bgWidth = 200; }
    moon.AlertManager.getIns().alertRoll(title, bgWidth);
};
//----------------------------------------------
var moon;
(function (moon) {
    var FONT = (function () {
        function FONT() {
        }
        FONT.fontName = "黑体";
        return FONT;
    }());
    moon.FONT = FONT;
    __reflect(FONT.prototype, "moon.FONT");
    var Const = (function () {
        function Const() {
        }
        /**布局 横版*/
        Const.HORIZONTAL = "horizontal";
        /**布局 竖版*/
        Const.VERTICAL = "vertical";
        /**形状 方块*/
        Const.SHAPE_RECT = "shape rect";
        /**形状 圆角方块*/
        Const.SHAPE_RECT_ROUND = "shape rect round";
        /**形状 圆块*/
        Const.SHAPE_CIRCLE = "shape circle";
        /**版本 调试*/
        Const.VER_DEBUG = "debug";
        /**版本 发布*/
        Const.VER_RELEASE = "release";
        return Const;
    }());
    moon.Const = Const;
    __reflect(Const.prototype, "moon.Const");
    /**颜色 */
    var Color = (function () {
        function Color() {
        }
        Object.defineProperty(Color, "random", {
            get: function () { return Math.random() * 0XFFFFFF; },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Color, "white", {
            get: function () { return 0XFFFFFF; },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Color, "black", {
            get: function () { return 0X000000; },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Color, "gray", {
            get: function () { return 0X666666; },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Color, "red", {
            get: function () { return 0XFF0000; },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Color, "green", {
            get: function () { return 0X00FF00; },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Color, "bule", {
            get: function () { return 0X0000FF; },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Color, "skinNormal", {
            get: function () { return 0X15191C; },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Color, "skinDown", {
            get: function () { return 0X999999; },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Color, "titleBackground", {
            get: function () { return 0X20262B; },
            enumerable: true,
            configurable: true
        });
        ;
        Color.getRandomArray = function (count) {
            var colors = [];
            for (var i = 0; i < count; i++)
                colors.push(Math.random() * 0XFFFFFF);
            return colors;
        };
        ;
        /** 可改变颜色的亮暗,value值是-255到255*/
        Color.lightenDarkenColor = function (color, value) {
            var r = (color >> 16) + value;
            if (r > 255)
                r = 255;
            else if (r < 0)
                r = 0;
            var b = ((color >> 8) & 0x00FF) + value;
            if (b > 255)
                b = 255;
            else if (b < 0)
                b = 0;
            var g = (color & 0x0000FF) + value;
            if (g > 255)
                g = 255;
            else if (g < 0)
                g = 0;
            return (g | (b << 8) | (r << 16));
        };
        return Color;
    }());
    moon.Color = Color;
    __reflect(Color.prototype, "moon.Color");
    /**皮肤 */
    var Skin = (function () {
        function Skin() {
        }
        Object.defineProperty(Skin, "randomRect", {
            get: function () { return moon.MoonUI.getRect(60, 60, moon.Color.random); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "randomCircle", {
            get: function () { return moon.MoonUI.getCircle(50, moon.Color.random); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "pointNormal", {
            /**默认点 */
            get: function () { return moon.MoonUI.getCircle(6, moon.Color.black); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "pointDown", {
            get: function () { return moon.MoonUI.getCircle(6, moon.Color.gray); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "buttonNormal", {
            /**默认按钮 */
            get: function () { return moon.MoonUI.getRect(60, 60, moon.Color.skinNormal); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "buttonDown", {
            get: function () { return moon.MoonUI.getRect(60, 60, moon.Color.skinDown); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "radioOff", {
            /**默认单选框 */
            get: function () { return moon.MoonUI.getRadioCircle(moon.Color.white, moon.Color.white); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "radioOn", {
            get: function () { return moon.MoonUI.getRadioCircle(moon.Color.white, moon.Color.black, 1); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "checkBoxOff", {
            /**默认复选框 */
            get: function () { return moon.MoonUI.getCheckBoxRect(moon.Color.white, moon.Color.white); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "checkBoxOn", {
            get: function () { return moon.MoonUI.getCheckBoxRect(moon.Color.white, moon.Color.black, 1); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "switchOff", {
            /**默认开关 */
            get: function () { return moon.MoonUI.getSwitch(moon.Color.skinNormal, moon.Color.white); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "switchOn", {
            get: function () { return moon.MoonUI.getSwitch(moon.Color.skinNormal, moon.Color.white, 1); },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(Skin, "progressBackground", {
            /**默认进度条 */
            get: function () { return moon.MoonUI.getRect(300, 20, moon.Color.skinNormal); },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Skin, "progressValue", {
            get: function () { return moon.MoonUI.getRect(300, 20, moon.Color.skinDown); },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Skin, "sliderBackground", {
            /**默认滑动器 */
            get: function () { return moon.MoonUI.getRect(300, 10, moon.Color.skinNormal); },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Skin, "sliderValue", {
            get: function () { return moon.MoonUI.getRect(300, 10, moon.Color.skinDown); },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Skin, "sliderBar", {
            get: function () { return moon.MoonUI.getCircle(15, moon.Color.white); },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Skin, "scrollBar", {
            /**默认滚动条 */
            get: function () { return moon.MoonUI.getRect(10, 10, moon.Color.skinNormal); },
            enumerable: true,
            configurable: true
        });
        Skin.getRodatioButton = function (label) {
            var btn = new BasicButton(moon.Skin.radioOff, moon.Skin.radioOn);
            btn.skinAutoScale = false;
            btn.label = label;
            btn.labelColor = moon.Color.black;
            btn.setLabelPoint(40, 0);
            return btn;
        };
        Skin.getCheckBox = function (label) {
            var skins = [moon.Skin.checkBoxOff, moon.Skin.checkBoxOff, moon.Skin.checkBoxOn, moon.Skin.checkBoxOn];
            var btn = new moon.MoreSkinButton(skins);
            btn.skinAutoScale = false;
            btn.label = label;
            btn.toggleSwitch = true;
            btn.labelColor = moon.Color.black;
            btn.setLabelPoint(50, 2);
            return btn;
        };
        return Skin;
    }());
    moon.Skin = Skin;
    __reflect(Skin.prototype, "moon.Skin");
    /**
     * ...
     * 简单的布局
     * @author vinson
     */
    var SimpleLayout = (function () {
        function SimpleLayout() {
        }
        /**参数：数组,X轴个数,X轴距离,Y轴距离,X轴位置,Y轴位置,正排/反排 */
        SimpleLayout.displayRank = function (array, xNum, xDis, yDis, x, y, sign) {
            if (xNum === void 0) { xNum = 1; }
            if (xDis === void 0) { xDis = 0; }
            if (yDis === void 0) { yDis = 0; }
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            if (sign === void 0) { sign = 1; }
            var display;
            for (var i = 0; i < array.length; i++) {
                display = array[i];
                display.x = x + Math.floor(i % xNum) * (display.width + xDis) * sign;
                display.y = y + Math.floor(i / xNum) * (display.height + yDis) * sign;
            }
        };
        return SimpleLayout;
    }());
    moon.SimpleLayout = SimpleLayout;
    __reflect(SimpleLayout.prototype, "moon.SimpleLayout");
    /**
     * ...
     * 默认参数x轴,y轴,w宽,h高,r半径,c颜色,ew圆角宽,eh圆家高
     * @author vinson
     */
    var MoonUI = (function () {
        function MoonUI() {
        }
        Object.defineProperty(MoonUI, "randomColor", {
            /**得到随机色*/
            get: function () {
                return Math.random() * 0XFFFFFF;
            },
            enumerable: true,
            configurable: true
        });
        /**得到矩形框*/
        MoonUI.getLineRect = function (w, h, c, s, x, y) {
            if (c === void 0) { c = 0; }
            if (s === void 0) { s = 1; }
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            var node = new Sprite();
            node.graphics.lineStyle(s, c);
            node.graphics.drawRect(x, y, w, h);
            node.graphics.endFill();
            return node;
        };
        /**得到圆形框*/
        MoonUI.getLineCircle = function (r, c, s, x, y) {
            if (c === void 0) { c = 0; }
            if (s === void 0) { s = 1; }
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            var node = new Sprite();
            node.graphics.lineStyle(s, c);
            node.graphics.drawCircle(x, y, r);
            node.graphics.endFill();
            return node;
        };
        /**得到渐变矩形 a为角度偏移率0,0.5,1,2分别为四个正方向*/
        MoonUI.getMatrixRect = function (w, h, c1, c2, a) {
            if (c1 === void 0) { c1 = 0; }
            if (c2 === void 0) { c2 = 0; }
            if (a === void 0) { a = 0; }
            var node = new Sprite();
            var matrix = new egret.Matrix();
            matrix.createGradientBox(w, h, Math.PI * a, 0, 0);
            node.graphics.beginGradientFill(egret.GradientType.LINEAR, [c1, c2], [1, 1], [0, 255], matrix);
            node.graphics.drawRect(0, 0, w, h);
            node.graphics.endFill();
            return node;
        };
        /**得到矩形*/
        MoonUI.getRect = function (w, h, c, x, y) {
            if (c === void 0) { c = 0; }
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            var s = new Sprite();
            s.graphics.beginFill(c);
            s.graphics.drawRect(x, y, w, h);
            s.graphics.endFill();
            return s;
        };
        /**得到矩形和一个X*/
        MoonUI.getRectAndX = function (w, h, c, x, y) {
            if (c === void 0) { c = 0; }
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            var s = this.getRect(w, h, c, x, y);
            s.addChild(this.getX(w, h, c, 1, x, y));
            return s;
        };
        /**得到矩形和一个X*/
        MoonUI.getX = function (w, h, c, s, x, y) {
            if (c === void 0) { c = 0; }
            if (s === void 0) { s = 1; }
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            var container = new Sprite;
            var l1 = new Sprite;
            l1.graphics.lineStyle(s, c);
            l1.graphics.moveTo(0, 0);
            l1.graphics.lineTo(w, h);
            var l2 = new Sprite;
            l2.graphics.lineStyle(s, c);
            l2.graphics.moveTo(w, 0);
            l2.graphics.lineTo(0, h);
            container.addChild(l1);
            container.addChild(l2);
            return container;
        };
        /**得到圆角矩形*/
        MoonUI.getRoundRect = function (w, h, c, ew, eh, x, y) {
            if (c === void 0) { c = 0; }
            if (ew === void 0) { ew = 5; }
            if (eh === void 0) { eh = 5; }
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            var s = new Sprite();
            s.graphics.beginFill(c);
            s.graphics.drawRoundRect(x, y, w, h, ew, eh);
            s.graphics.endFill();
            return s;
        };
        /**得到圆形*/
        MoonUI.getCircle = function (r, c, x, y) {
            if (c === void 0) { c = 0; }
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            var s = new Sprite();
            s.graphics.beginFill(c);
            s.graphics.drawCircle(x, y, r);
            s.graphics.endFill();
            return s;
        };
        /**得到多边形,side边数,rotation角度*/
        MoonUI.getPolygon = function (side, r, c, rotation) {
            if (side === void 0) { side = 3; }
            if (r === void 0) { r = 10; }
            if (c === void 0) { c = 0; }
            if (rotation === void 0) { rotation = 0; }
            var s = new Sprite;
            s.rotation = rotation;
            s.graphics.beginFill(c);
            for (var i = 0; i <= side; i++) {
                var lineX = Math.cos((i * (360 / side) * Math.PI / 180)) * r;
                var lineY = Math.sin((i * (360 / side) * Math.PI / 180)) * r;
                if (i == 0)
                    s.graphics.moveTo(lineX, lineY);
                else
                    s.graphics.lineTo(lineX, lineY);
            }
            s.graphics.endFill();
            return s;
        };
        /**得到圆角矩形与三角形合体rc是正方形颜色,pc是三角形颜色*/
        MoonUI.getArrowRoundRect = function (w, h, rc, pc, rotation) {
            if (pc === void 0) { pc = 0; }
            if (rotation === void 0) { rotation = 0; }
            var s = new Sprite;
            s.addChild(this.getRoundRect(w, h, rc));
            var p = this.getPolygon(3, w / 3, pc, 30 + rotation);
            p.x = s.width >> 1;
            p.y = s.height >> 1;
            s.addChild(p);
            return s;
        };
        /**得到滚动条的bar*/
        MoonUI.getScrollLineBar = function (w, h, c) {
            var s = new Sprite;
            var _h = h / 3;
            for (var i = 0; i < 3; i++) {
                var r = this.getRect(w, 1, c, 0, i * _h);
                s.addChild(r);
            }
            return s;
        };
        /**得到圆角矩形-加*/
        MoonUI.getAddRoundRect = function (w, h, c) {
            var s = new Sprite;
            s.addChild(this.getRoundRect(w, h, c));
            var r1 = this.getRect(w / 2, 2, 0, w / 4, h / 2 - 1);
            var r2 = this.getRect(2, h / 2, 0, w / 2 - 1, h / 4);
            s.addChild(r1);
            s.addChild(r2);
            return s;
        };
        /**得到圆角矩形-减*/
        MoonUI.getRemoveRoundRect = function (w, h, c) {
            var s = new Sprite;
            s.addChild(this.getRoundRect(w, h, c));
            var r = this.getRect(w / 2, 2, 0, w / 4, h / 2 - 1);
            s.addChild(r);
            return s;
        };
        /**得到带文字的圆角方形*/
        MoonUI.getRoundRectText = function (w, h, c, str) {
            if (str === void 0) { str = "click"; }
            var s = new Sprite;
            s.addChild(this.getRoundRect(w, h, c));
            var text = new TextField;
            text.name = "text";
            text.text = str;
            text.x = (s.width - text.width) >> 1;
            text.y = (s.height - text.height) >> 1;
            s.addChild(text);
            return s;
        };
        /**得到矩形-switchButton bc背景颜色，gc钩选的颜色,type为0是没有钩为1是有钩*/
        MoonUI.getSwitch = function (bc, gc, type) {
            if (bc === void 0) { bc = 0XFFFFFF; }
            if (gc === void 0) { gc = 0; }
            if (type === void 0) { type = 0; }
            var node = moon.MoonUI.getRoundRect(80, 50, bc, 60, 60);
            node.addChild(moon.MoonUI.getCircle(22, gc, type == 0 ? 25 : 55, 25));
            return node;
        };
        /**得到矩形-复选框 bc背景颜色，gc钩的颜色,type为0是没有钩为1是有钩*/
        MoonUI.getCheckBoxRect = function (bc, gc, type) {
            if (bc === void 0) { bc = 0XFFFFFF; }
            if (gc === void 0) { gc = 0; }
            if (type === void 0) { type = 0; }
            var s = new Sprite;
            s.addChild(this.getRect(40, 40, bc));
            if (type == 1) {
                var r = new Sprite;
                r.graphics.beginFill(gc);
                r.graphics.moveTo(0, 20);
                r.graphics.lineTo(20, 36);
                r.graphics.lineTo(44, 8);
                r.graphics.lineTo(36, 0);
                r.graphics.lineTo(20, 18);
                r.graphics.lineTo(12, 8);
                r.graphics.lineTo(0, 20);
                s.addChild(r);
            }
            return s;
        };
        /**得到矩形-单选框 bc背景颜色，gc钩的颜色,type为0是没有圆为1是有圆*/
        MoonUI.getRadioCircle = function (bc, gc, type) {
            if (bc === void 0) { bc = 0XFFFFFF; }
            if (gc === void 0) { gc = 0; }
            if (type === void 0) { type = 0; }
            var s = new Sprite;
            s.addChild(this.getCircle(16, bc, 16, 16));
            s.graphics.lineStyle(1, 0);
            if (type == 1) {
                var r = this.getCircle(8, gc, 16, 16);
                s.addChild(r);
            }
            return s;
        };
        /**得到矩形-网格
         * rect.x是x轴数量
         * rect.y是y轴数量
         * rect.width是网格宽
         * rect.height是网格高
         * lc网格线颜色
         * */
        MoonUI.getGridding = function (rect, c) {
            if (c === void 0) { c = 0; }
            var s = new Sprite;
            s.graphics.lineStyle(0.1, c);
            var disx = rect.width / rect.x;
            var disy = rect.height / rect.y;
            for (var i = 0; i < rect.x; i++) {
                s.graphics.moveTo(0, i * disy);
                s.graphics.lineTo(rect.width, i * disy);
            }
            for (i = 0; i < rect.y; i++) {
                s.graphics.moveTo(i * disx, 0);
                s.graphics.lineTo(i * disx, rect.height);
            }
            return s;
        };
        /***得到爱心 */
        MoonUI.getHeart = function (r, c) {
            if (r === void 0) { r = 15; }
            if (c === void 0) { c = 0XFF0000; }
            var s = new Sprite;
            s.graphics.beginFill(c);
            s.graphics.moveTo(0, 0);
            s.graphics.lineTo(0, -r * 2);
            s.graphics.cubicCurveTo(r, -r * 2.5, r * 2, -r * 1.5, 0, 0);
            s.graphics.moveTo(0, 0);
            s.graphics.lineTo(0, -r * 2);
            s.graphics.cubicCurveTo(-r, -r * 2.5, -r * 2, -r * 1.5, 0, 0);
            s.graphics.endFill();
            s.anchorOffsetX = -s.width / 2;
            s.anchorOffsetY = -s.height;
            return s;
        };
        return MoonUI;
    }());
    moon.MoonUI = MoonUI;
    __reflect(MoonUI.prototype, "moon.MoonUI");
    //--------------
    var LogManager = (function () {
        function LogManager() {
        }
        LogManager.getIns = function () {
            if (this.instance == null) {
                this.instance = new LogManager();
            }
            return this.instance;
        };
        /**请先调用初始化函数 */
        LogManager.prototype.init = function (stage) {
            var txt = (new Label).textField;
            txt.textAlign = egret.HorizontalAlign.LEFT;
            stage.addChild(txt);
            this.txtSimple = txt;
            var txt = (new Label).textField;
            txt.size = 25;
            stage.addChild(txt);
            this.txtMessage = txt;
        };
        /**每次都覆盖上一次信息 */
        LogManager.prototype.debug = function (value) {
            this.txtSimple.text = value;
        };
        /**每次都覆盖上一次信息 */
        LogManager.prototype.log = function (value) {
            if (GameData.version == Const.VER_DEBUG)
                this.txtSimple.text = value;
        };
        /**显示所有信息 */
        LogManager.prototype.logMessage = function (value) {
            if (GameData.version == Const.VER_DEBUG)
                this.txtMessage.appendText(value + "\n");
        };
        LogManager.prototype.setLogColor = function (color) {
            this.txtSimple.textColor = color;
        };
        LogManager.prototype.setLogMessageColor = function (color) {
            this.txtMessage.textColor = color;
        };
        return LogManager;
    }());
    moon.LogManager = LogManager;
    __reflect(LogManager.prototype, "moon.LogManager");
    //--------------
    var AlertManager = (function () {
        function AlertManager() {
        }
        AlertManager.getIns = function () {
            if (this.instance == null) {
                this.instance = new AlertManager();
            }
            return this.instance;
        };
        /**请先调用初始化函数 */
        AlertManager.prototype.init = function (stage) {
            this.stage = stage;
        };
        AlertManager.prototype.alertAuto = function (title, closeTime) {
            if (title === void 0) { title = "自动关闭的提示或警告"; }
            if (closeTime === void 0) { closeTime = 3; }
            var a = new AlertAutoBar(title, closeTime);
            if (this.stage)
                this.stage.addChild(a);
            else
                trace("调用alertAuto时请先执行AlertManager的init初始化函数");
            return a;
        };
        AlertManager.prototype.alert = function (title) {
            if (title === void 0) { title = "手动关闭的提示或警告"; }
            var a = new AlertBar(title);
            if (this.stage)
                this.stage.addChild(a);
            else
                trace("调用alertAuto时请先执行AlertManager的init初始化函数");
            return a;
        };
        AlertManager.prototype.alertRoll = function (title, bgWidth) {
            if (title === void 0) { title = "提示或警告"; }
            if (bgWidth === void 0) { bgWidth = 200; }
            var a = new AlertRollBar(title, bgWidth);
            if (this.stage)
                this.stage.addChild(a);
            else
                trace("调用alertAuto时请先执行AlertManager的init初始化函数");
            return a;
        };
        return AlertManager;
    }());
    moon.AlertManager = AlertManager;
    __reflect(AlertManager.prototype, "moon.AlertManager");
    var TipsManager = (function () {
        function TipsManager() {
            this.bgName = "tips_png"; //TIPS的背景图片
        }
        TipsManager.getIns = function () {
            if (this.instance == null) {
                this.instance = new TipsManager();
            }
            return this.instance;
        };
        /**请先调用初始化函数 */
        TipsManager.prototype.init = function (stage) {
            this.stage = stage;
        };
        TipsManager.prototype.simpleTips = function (value, pos) {
            if (this.tipsView == null) {
                this.tipsView = new moon.BasicTips(this.bgName);
                this.tipsView.setValue(value);
                this.stage.addChild(this.tipsView);
                this.setPosition(pos);
                this.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.removeTips, this);
            }
        };
        TipsManager.prototype.setPosition = function (pos) {
            if (pos) {
                this.tipsView.x = pos.x - (this.tipsView.width >> 1);
                this.tipsView.y = pos.y - this.tipsView.height * 2;
                if (this.tipsView.y < 0) {
                    this.tipsView.y = pos.y;
                }
                if ((this.tipsView.y + this.tipsView.height) > this.stage.stageHeight) {
                    this.tipsView.y = pos.y - (this.tipsView.height + 50);
                }
                if (this.tipsView.x < 0) {
                    this.tipsView.x = pos.x + 50;
                }
                if ((this.tipsView.x + this.tipsView.width) > this.stage.stageWidth) {
                    this.tipsView.x = pos.x - (this.tipsView.width + 50);
                }
            }
        };
        TipsManager.prototype.removeTips = function () {
            this.stage.removeEventListener(egret.TouchEvent.TOUCH_END, this.removeTips, this);
            var parent = this.tipsView.parent;
            if (parent != null) {
                parent.removeChild(this.tipsView);
                this.tipsView = null;
            }
        };
        return TipsManager;
    }());
    moon.TipsManager = TipsManager;
    __reflect(TipsManager.prototype, "moon.TipsManager");
    var MoonEvent = (function (_super) {
        __extends(MoonEvent, _super);
        function MoonEvent(type, data, currentTarget) {
            if (type === void 0) { type = ""; }
            if (data === void 0) { data = null; }
            if (currentTarget === void 0) { currentTarget = null; }
            var _this = _super.call(this) || this;
            _this.type = type;
            _this.data = data;
            _this.currentTarget = currentTarget;
            return _this;
        }
        //button event
        MoonEvent.MOUSE_OVER = "event-over"; //移进
        MoonEvent.MOUSE_OUT = "event-out"; //移出
        MoonEvent.MOUSE_DOWN = "event-down"; //点下
        MoonEvent.MOUSE_MOVE = "event-move"; //移动
        MoonEvent.MOUSE_UP = "event-up"; //弹开
        MoonEvent.CLICK = "event-click"; //单击
        //tabbar event
        MoonEvent.CHANGE = "change"; //更换
        MoonEvent.COMPLETE = "complete"; //完成
        MoonEvent.RENDER_COMPLETE = "render complete"; //渲染完成
        MoonEvent.UPDATE = "update"; //更新
        MoonEvent.START = "start"; //开始
        MoonEvent.MOVE = "move"; //移动
        MoonEvent.OVER = "over"; //结束
        MoonEvent.PAUSE = "pause"; //暂停
        MoonEvent.STOP = "stop"; //停止
        MoonEvent.PLAY = "play"; //播放
        MoonEvent.OPEN = "open"; //开启
        MoonEvent.CLOSE = "close"; //关闭
        return MoonEvent;
    }(egret.EventDispatcher));
    moon.MoonEvent = MoonEvent;
    __reflect(MoonEvent.prototype, "moon.MoonEvent");
    var MoonDisplayObject = (function (_super) {
        __extends(MoonDisplayObject, _super);
        function MoonDisplayObject() {
            var _this = _super.call(this) || this;
            _this._type = Const.SHAPE_RECT;
            _this._color = 0;
            _this.display = new Sprite;
            _this.bg = new Sprite;
            return _this;
        }
        Object.defineProperty(MoonDisplayObject.prototype, "type", {
            get: function () { return this._type; },
            set: function (value) { this._type = value; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(MoonDisplayObject.prototype, "color", {
            get: function () { return this._color; },
            set: function (value) { this._color = value; this._data.c = value; this.draw(); },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(MoonDisplayObject.prototype, "data", {
            /**{w:1,h:1,r:1,c:1,ew:1,eh:1} */
            set: function (value) { this._data = value; this.draw(); },
            enumerable: true,
            configurable: true
        });
        MoonDisplayObject.prototype.draw = function () {
            this._color = this._data.c;
            this.display.graphics.clear();
            this.display = this.getDisplay(this._data);
            this.addChild(this.display);
            this.setPosition();
        };
        MoonDisplayObject.prototype.setPosition = function () {
            if (this._hasBg && this.type != Const.SHAPE_CIRCLE) {
                this.display.x = (this.bg.width - this.display.width) >> 1;
                this.display.y = (this.bg.height - this.display.height) >> 1;
            }
        };
        MoonDisplayObject.prototype.setBackground = function (color, side) {
            if (side === void 0) { side = 1; }
            this._hasBg = true;
            var d = this._data;
            var o = {};
            for (var i in d) {
                o[i] = d[i];
            }
            o.c = color;
            if (o.w)
                o.w = o.w + side * 2;
            if (o.h)
                o.h = o.h + side * 2;
            if (o.r)
                o.r = o.r + side;
            this.bg.graphics.clear();
            this.bg = this.getDisplay(o);
            this.addChildAt(this.bg, 0);
            this.setPosition();
        };
        MoonDisplayObject.prototype.getDisplay = function (o) {
            switch (this.type) {
                case Const.SHAPE_RECT:
                    return MoonUI.getRect(o.w, o.h, o.c);
                case Const.SHAPE_RECT_ROUND:
                    return MoonUI.getRoundRect(o.w, o.h, o.c, o.ew, o.eh);
                case Const.SHAPE_CIRCLE:
                    return MoonUI.getCircle(o.r, o.c);
            }
        };
        return MoonDisplayObject;
    }(Sprite));
    moon.MoonDisplayObject = MoonDisplayObject;
    __reflect(MoonDisplayObject.prototype, "moon.MoonDisplayObject");
    var MoonContainer = (function (_super) {
        __extends(MoonContainer, _super);
        function MoonContainer() {
            var _this = _super.call(this) || this;
            _this.dataEvent = new Object;
            _this.init();
            _this.once(egret.Event.ADDED_TO_STAGE, _this.addToStage, _this);
            return _this;
        }
        MoonContainer.prototype.addToStage = function () {
            this.render();
        };
        /**加载到舞台之前调用 */
        MoonContainer.prototype.init = function () {
        };
        /**加载到舞台之后调用 */
        MoonContainer.prototype.render = function () {
            this.stageWidth = this.stage.stageWidth;
            this.stageHeight = this.stage.stageHeight;
        };
        /**发布事件*/
        MoonContainer.prototype.dispEvent = function (type, data, dataType) {
            if (data === void 0) { data = null; }
            if (dataType === void 0) { dataType = null; }
            if (this.dataEvent) {
                var fun = this.dataEvent[type];
                if (fun != null) {
                    var moonEvent = new MoonEvent;
                    moonEvent.currentTarget = this;
                    moonEvent.data = data;
                    moonEvent.type = type;
                    moonEvent.dataType = dataType;
                    if (fun["this"]) {
                        fun.apply(fun["this"], [moonEvent]);
                    }
                    else {
                        fun(moonEvent);
                    }
                }
            }
        };
        /**帧听事件*/
        MoonContainer.prototype.addEvent = function (type, listener, thisObj) {
            if (thisObj === void 0) { thisObj = null; }
            if (this.dataEvent && this.dataEvent[type] == null) {
                listener["this"] = thisObj;
                this.dataEvent[type] = listener;
            }
        };
        /**删除事件*/
        MoonContainer.prototype.removeEvent = function (type, listener) {
            if (this.dataEvent && this.dataEvent[type]) {
                delete this.dataEvent[type];
            }
        };
        /**把自己从父级删除*/
        MoonContainer.prototype.removeFromParent = function (value) {
            if (value === void 0) { value = false; }
            var _parent = this.parent;
            if (value)
                this.dispose();
            if (_parent && _parent.contains(this))
                _parent.removeChild(this);
            _parent = null;
        };
        /**删除所有的*/
        MoonContainer.prototype.removeChildAll = function (beginIndex, endIndex, dispose) {
            if (beginIndex === void 0) { beginIndex = 0; }
            if (endIndex === void 0) { endIndex = 2147483647; }
            if (dispose === void 0) { dispose = false; }
            if (endIndex < 0 || endIndex >= this.numChildren)
                endIndex = this.numChildren - 1;
            for (var i = beginIndex; i <= endIndex; ++i)
                this.removeChildIndex(beginIndex, dispose);
        };
        /**删除index层的*/
        MoonContainer.prototype.removeChildIndex = function (beginIndex, dispose) {
            if (beginIndex >= 0 || beginIndex < this.numChildren) {
                var basicContent = this.getChildAt(beginIndex);
                if (basicContent instanceof MoonContainer) {
                    basicContent.removeFromParent(dispose);
                }
                else {
                    var display = this.getChildAt(beginIndex);
                    if (display.parent)
                        display.parent.removeChild(display);
                }
            }
        };
        /**销毁*/
        MoonContainer.prototype.dispose = function () {
            this.removeChildAll(0, -1, true);
            this.dataEvent = null;
            this.stageWidth = null;
            this.stageHeight = null;
        };
        return MoonContainer;
    }(DisplayObjectContainer));
    moon.MoonContainer = MoonContainer;
    __reflect(MoonContainer.prototype, "moon.MoonContainer");
    var BasicView = (function (_super) {
        __extends(BasicView, _super);
        function BasicView() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        BasicView.prototype.createText = function (x, y, s) {
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            if (s === void 0) { s = ""; }
            var text = (new Label).textField;
            text.x = x;
            text.y = y;
            text.text = s;
            this.addChild(text);
            return text;
        };
        BasicView.prototype.createRect = function (w, h, c, x, y) {
            if (c === void 0) { c = 0; }
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            var sprite = moon.MoonUI.getRect(w, h, c, x, y);
            this.addChild(sprite);
            return sprite;
        };
        BasicView.prototype.createCircle = function (r, c, x, y) {
            if (c === void 0) { c = 0; }
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            var sprite = moon.MoonUI.getCircle(r, c, x, y);
            this.addChild(sprite);
            return sprite;
        };
        BasicView.prototype.createRectBySprite = function (s, w, h, c, x, y) {
            if (c === void 0) { c = 0; }
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            s.graphics.clear();
            s.graphics.beginFill(c);
            s.graphics.drawRect(x, y, w, h);
            s.graphics.endFill();
        };
        /**创建纯色背景 */
        BasicView.prototype.createBackground = function (c, a) {
            if (c === void 0) { c = 0; }
            if (a === void 0) { a = 1; }
            var s = this.createRect(this.stageWidth, this.stageHeight, c);
            s.alpha = a;
            s.touchEnabled = true; //用于阻止下层点击事件
            return s;
        };
        /**创建渐变色背景 */
        BasicView.prototype.createBgGradientFill = function (c1, c2) {
            if (c1 === void 0) { c1 = 0X017AC3; }
            if (c2 === void 0) { c2 = 0XDDDDDD; }
            var w = this.stageWidth;
            var h = this.stageHeight;
            var matrix = new egret.Matrix();
            matrix.createGradientBox(w, h, Math.PI / 2);
            var sprite = new Sprite;
            sprite.graphics.beginGradientFill(egret.GradientType.LINEAR, [c1, c2], [1, 1], [0, 255], matrix);
            sprite.graphics.drawRect(0, 0, w, h);
            this.addChild(sprite);
            return sprite;
        };
        return BasicView;
    }(MoonContainer));
    moon.BasicView = BasicView;
    __reflect(BasicView.prototype, "moon.BasicView");
    var GameView = (function (_super) {
        __extends(GameView, _super);
        function GameView() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        GameView.prototype.play = function () {
            this.stop();
            this.isPlay = true;
            egret.startTick(this.loop, this);
        };
        GameView.prototype.stop = function () {
            this.isPlay = false;
            egret.stopTick(this.loop, this);
        };
        GameView.prototype.loop = function (n) {
            traceSimple(n);
            return true;
        };
        GameView.prototype.createButton = function (name, x, y) {
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            var btn = new moon.BasicButton;
            btn.label = name;
            btn.x = x;
            btn.y = y;
            this.addChild(btn);
            return btn;
        };
        return GameView;
    }(BasicView));
    moon.GameView = GameView;
    __reflect(GameView.prototype, "moon.GameView");
    /**九宫格*/
    var Scale9Image = (function (_super) {
        __extends(Scale9Image, _super);
        function Scale9Image(name, rect) {
            if (rect === void 0) { rect = null; }
            var _this = _super.call(this) || this;
            if (RES.hasRes(name)) {
                _this.texture = RES.getRes(name);
                _this.scale9Grid = rect || new Rectangle(8, 8, 2, 2);
            }
            else {
                egret.error("找不到资源：" + name);
            }
            return _this;
        }
        return Scale9Image;
    }(Bitmap));
    moon.Scale9Image = Scale9Image;
    __reflect(Scale9Image.prototype, "moon.Scale9Image");
    var BasicTips = (function (_super) {
        __extends(BasicTips, _super);
        function BasicTips(skinName) {
            var _this = _super.call(this) || this;
            _this.side = 14; //文字离边框的距离
            _this.lineSpacing = 4; //行间距
            _this.image = new Scale9Image(skinName);
            _this.addChild(_this.image);
            _this.text = (new Label).textField;
            _this.text.textAlign = egret.HorizontalAlign.CENTER;
            _this.text.verticalAlign = egret.VerticalAlign.MIDDLE;
            _this.text.lineSpacing = _this.lineSpacing;
            _this.addChild(_this.text);
            return _this;
        }
        /**设置普通文字*/
        BasicTips.prototype.setValue = function (value) {
            this.text.text = value;
            this.setCenter();
        };
        /**设置富文字 {text:"string",style:{"size":50,"textColor":0}}*/
        BasicTips.prototype.setTextFlow = function (textFlow) {
            this.text.textFlow = textFlow;
            this.setCenter();
        };
        BasicTips.prototype.setCenter = function () {
            var image = this.image;
            var text = this.text;
            var side = this.side;
            var w = text.width + side;
            var h = text.height + side;
            image.width = w;
            image.height = h;
            text.x = text.y = side >> 1;
        };
        return BasicTips;
    }(MoonContainer));
    moon.BasicTips = BasicTips;
    __reflect(BasicTips.prototype, "moon.BasicTips");
    var Label = (function (_super) {
        __extends(Label, _super);
        function Label(str, c) {
            if (str === void 0) { str = ""; }
            if (c === void 0) { c = 0XFFFFFF; }
            var _this = _super.call(this) || this;
            _this.text = new TextField;
            _this.text.textAlign = egret.HorizontalAlign.LEFT;
            _this.text.verticalAlign = egret.VerticalAlign.MIDDLE;
            _this.text.text = str;
            _this.text.textColor = c;
            _this.text.fontFamily = moon.FONT.fontName;
            _this.addChild(_this.text);
            return _this;
        }
        Object.defineProperty(Label.prototype, "textField", {
            get: function () {
                return this.text;
            },
            enumerable: true,
            configurable: true
        });
        return Label;
    }(MoonContainer));
    moon.Label = Label;
    __reflect(Label.prototype, "moon.Label");
    var BasicButton = (function (_super) {
        __extends(BasicButton, _super);
        function BasicButton(normal, down) {
            if (normal === void 0) { normal = null; }
            if (down === void 0) { down = null; }
            var _this = _super.call(this) || this;
            /**皮肤大小随字体大小变化 */
            _this.skinAutoScale = true;
            _this.statusNormal = normal || Skin.buttonNormal;
            _this.statusDown = down || Skin.buttonDown;
            _this.skinContainer = new DisplayObjectContainer;
            _this.addChild(_this.skinContainer);
            _this.updateSkin(_this.statusNormal);
            _this.text = (new Label).textField;
            _this.addChild(_this.text);
            _this.open();
            return _this;
        }
        BasicButton.prototype.open = function () {
            this.close();
            this.touchEnabled = true;
            this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouch, this);
        };
        BasicButton.prototype.close = function () {
            this.touchEnabled = false;
            this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouch, this);
            if (this.stage)
                this.stage.removeEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
        };
        BasicButton.prototype.setLabelPoint = function (x, y) {
            this.text.anchorOffsetX = 0;
            this.text.anchorOffsetY = 0;
            this.text.x = x;
            this.text.y = y;
        };
        Object.defineProperty(BasicButton.prototype, "labelCircle", {
            set: function (value) {
                this.text.text = value;
                this.skinAutoScale = false;
                this.text.x = this.text.y = 0;
                this.text.anchorOffsetX = this.text.textWidth >> 1;
                this.text.anchorOffsetY = this.text.textHeight >> 1;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BasicButton.prototype, "labelColor", {
            set: function (value) {
                this.text.textColor = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BasicButton.prototype, "label", {
            get: function () {
                return this.text.text;
            },
            set: function (value) {
                this.text.text = value;
                var width = this.text.width + 20;
                this.setSkinSize();
                this.setTextPosition();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BasicButton.prototype, "textFild", {
            get: function () {
                return this.text;
            },
            enumerable: true,
            configurable: true
        });
        /**设置富文字 {text:"string",style:{"size":50,"textColor":0}}*/
        BasicButton.prototype.setTextFlow = function (textFlow) {
            this.text.textFlow = textFlow;
            this.setSkinSize();
            this.setTextPosition();
        };
        BasicButton.prototype.setSkinNormal = function () {
            this.updateSkin(this.statusNormal);
        };
        BasicButton.prototype.setSkinDown = function () {
            this.updateSkin(this.statusDown);
        };
        BasicButton.prototype.onTouch = function (e) {
            if (e.type == egret.TouchEvent.TOUCH_BEGIN) {
                this.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
                this.updateSkin(this.statusDown);
            }
            else {
                //		this.stage.removeEventListener(egret.TouchEvent.TOUCH_END,this.onTouch,this);
                this.updateSkin(this.statusNormal);
            }
            this.dispEvent(MoonEvent.CLICK);
        };
        Object.defineProperty(BasicButton.prototype, "textWidth", {
            get: function () {
                return this.text.width + 20;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BasicButton.prototype, "textHeight", {
            get: function () {
                return this.text.height + 20;
            },
            enumerable: true,
            configurable: true
        });
        BasicButton.prototype.setSkinSize = function () {
            if (this.skinAutoScale && this.text.text != "") {
                var scale = this.textWidth / this.statusNormal.width;
                if (this.statusNormal instanceof Bitmap) {
                    this.statusNormal.width = this.textWidth;
                    this.statusDown.width = this.textWidth;
                }
                else {
                    this.statusNormal.scaleX = this.statusDown.scaleX = scale;
                }
                var height = this.textHeight;
                if (height >= this.statusNormal.height) {
                    scale = height / this.statusNormal.height;
                    if (this.statusNormal instanceof Bitmap) {
                        this.statusNormal.height = this.textHeight;
                        this.statusDown.height = this.textHeight;
                    }
                    else {
                        this.statusNormal.scaleY = this.statusDown.scaleY = scale;
                    }
                }
            }
        };
        BasicButton.prototype.setTextPosition = function () {
            this.text.anchorOffsetX = this.text.width >> 1;
            this.text.anchorOffsetY = this.text.height >> 1;
            if (this.textWidth > this.statusNormal.width)
                this.text.x = this.textWidth >> 1;
            else
                this.text.x = this.statusNormal.width >> 1;
            if (this.textHeight > this.statusNormal.height)
                this.text.y = this.textHeight >> 1;
            else
                this.text.y = this.statusNormal.height >> 1;
        };
        BasicButton.prototype.updateSkin = function (skin) {
            this.skinContainer.removeChildren();
            this.skinContainer.addChild(skin);
        };
        BasicButton.prototype.dispose = function () {
            this.close();
            _super.prototype.dispose.call(this);
        };
        return BasicButton;
    }(MoonContainer));
    moon.BasicButton = BasicButton;
    __reflect(BasicButton.prototype, "moon.BasicButton", ["moon.IOnoff"]);
    /**类似多个皮肤按钮,构造函数的参数必须大于2个且必须是2的次方
     * 使用四个皮肤就可以模拟ToggleSwitch了
    */
    var MoreSkinButton = (function (_super) {
        __extends(MoreSkinButton, _super);
        function MoreSkinButton(skins) {
            var _this = _super.call(this, skins[0], skins[1]) || this;
            _this._currentPage = 0;
            _this.skins = skins;
            return _this;
        }
        /**更新到第几个按钮同时刷新皮肤 */
        MoreSkinButton.prototype.updatePage = function (value) {
            this.currentPage = value;
            this.setSkinNormal();
        };
        Object.defineProperty(MoreSkinButton.prototype, "currentPage", {
            get: function () {
                return this._currentPage;
            },
            set: function (value) {
                value = value * 2 == this.skins.length ? 0 : value;
                this._currentPage = value;
                this.statusNormal = this.skins[value * 2];
                this.statusDown = this.skins[(value * 2) + 1];
                this.setSkinSize();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(MoreSkinButton.prototype, "toggleSwitch", {
            set: function (value) {
                this._toggleSwitch = value;
            },
            enumerable: true,
            configurable: true
        });
        MoreSkinButton.prototype.onTouch = function (e) {
            if (e.type == egret.TouchEvent.TOUCH_END) {
                if (this._toggleSwitch) {
                    this.currentPage = 1 - this.currentPage;
                }
            }
            _super.prototype.onTouch.call(this, e);
        };
        return MoreSkinButton;
    }(BasicButton));
    moon.MoreSkinButton = MoreSkinButton;
    __reflect(MoreSkinButton.prototype, "moon.MoreSkinButton");
    /**基础的组件类*/
    var BasicBar = (function (_super) {
        __extends(BasicBar, _super);
        function BasicBar() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.items = [];
            _this.index = 0;
            return _this;
        }
        BasicBar.prototype.addItem = function (item) {
            this.items.push(item);
        };
        BasicBar.prototype.removeItem = function (item) {
            var index = this.items.indexOf(item);
            if (index >= 0)
                this.items.splice(index, 1);
        };
        BasicBar.prototype.hasItem = function (index) {
            return this.items.length > 0 && (index >= 0 && index < this.items.length);
        };
        BasicBar.prototype.getItem = function (index) {
            return this.items[index];
        };
        BasicBar.prototype.getNextItem = function () {
            return this.items[this.index++];
        };
        BasicBar.prototype.reset = function () {
            this.index = 0;
        };
        BasicBar.prototype.update = function () {
        };
        /**销毁*/
        BasicBar.prototype.dispose = function () {
            this.reset();
            while (this.hasItem(this.index)) {
                var item = this.getItem(this.index);
                this.removeItem(item);
                if (item instanceof MoonContainer) {
                    item.removeFromParent(true);
                }
            }
        };
        return BasicBar;
    }(BasicView));
    moon.BasicBar = BasicBar;
    __reflect(BasicBar.prototype, "moon.BasicBar", ["moon.IItem"]);
    /***进度条 */
    var ProgressBar = (function (_super) {
        __extends(ProgressBar, _super);
        function ProgressBar(bg, value) {
            if (bg === void 0) { bg = null; }
            if (value === void 0) { value = null; }
            var _this = _super.call(this) || this;
            _this._value = 0;
            _this.setSkin(bg, value);
            _this.addChild(_this.skinBg);
            _this.addChild(_this.skinValue);
            _this.text = (new Label).textField;
            _this.addChild(_this.text);
            return _this;
        }
        ProgressBar.prototype.setSkin = function (bg, value) {
            if (bg === void 0) { bg = null; }
            if (value === void 0) { value = null; }
            this.skinBg = bg || Skin.progressBackground;
            this.skinValue = value || Skin.progressValue;
        };
        Object.defineProperty(ProgressBar.prototype, "value", {
            get: function () {
                return this._value;
            },
            /**值只能是0－1之间 */
            set: function (v) {
                v = v < 0 ? 0 : v > 1 ? 1 : v;
                this._value = v;
                this.skinValue.scaleX = v;
            },
            enumerable: true,
            configurable: true
        });
        ProgressBar.prototype.showText = function (v, x, y) {
            if (x === void 0) { x = -1; }
            if (y === void 0) { y = -1; }
            this.text.text = v;
            if (x == -1)
                this.text.x = (this.skinBg.width - this.text.width) >> 1;
            else
                this.text.x = x;
            if (y == -1)
                this.text.y = this.skinBg.height + 5;
            else
                this.text.y = y;
        };
        return ProgressBar;
    }(MoonContainer));
    moon.ProgressBar = ProgressBar;
    __reflect(ProgressBar.prototype, "moon.ProgressBar");
    /***滑动器 */
    var SliderBar = (function (_super) {
        __extends(SliderBar, _super);
        function SliderBar(bg, value, bar) {
            if (bg === void 0) { bg = null; }
            if (value === void 0) { value = null; }
            if (bar === void 0) { bar = null; }
            var _this = _super.call(this, bg, value) || this;
            _this.skinBar = bar || Skin.sliderBar;
            _this.addChild(_this.skinBar);
            _this.skinBar.addEventListener(egret.TouchEvent.TOUCH_BEGIN, _this.onTouch, _this);
            _this.skinBar.touchEnabled = true;
            _this.layout();
            _this.value = 1;
            return _this;
        }
        SliderBar.prototype.setSkin = function (bg, value) {
            if (bg === void 0) { bg = null; }
            if (value === void 0) { value = null; }
            this.skinBg = bg || Skin.sliderBackground;
            this.skinValue = value || Skin.sliderValue;
        };
        SliderBar.prototype.onTouch = function (e) {
            switch (e.type) {
                case egret.TouchEvent.TOUCH_BEGIN:
                    this.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
                    this.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouch, this);
                    this.dispEvent(MoonEvent.START);
                    break;
                case egret.TouchEvent.TOUCH_MOVE:
                    this.moveDo(e.stageX, e.stageY);
                    this.dispEvent(MoonEvent.MOVE);
                    break;
                case egret.TouchEvent.TOUCH_END:
                    this.stage.removeEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
                    this.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouch, this);
                    this.dispEvent(MoonEvent.OVER);
                    break;
            }
        };
        SliderBar.prototype.moveDo = function (x, y) {
            var p = this.globalToLocal(x, y);
            var v;
            if (this.type == Const.HORIZONTAL)
                v = p.x / this.skinValue.width;
            else
                v = -p.y / this.skinValue.width;
            this.value = v;
        };
        Object.defineProperty(SliderBar.prototype, "value", {
            get: function () {
                return this._value;
            },
            /**值只能是0－1之间 */
            set: function (v) {
                v = v < 0 ? 0 : v > 1 ? 1 : v;
                this._value = v;
                this.skinValue.scaleX = v;
                if (this.type == Const.HORIZONTAL)
                    this.skinBar.x = this.skinValue.width * v;
                else
                    this.skinBar.y = -this.skinValue.width * v;
            },
            enumerable: true,
            configurable: true
        });
        /**横竖版布局，默认是横版布局 */
        SliderBar.prototype.layout = function (type, interval) {
            if (type === void 0) { type = Const.HORIZONTAL; }
            if (interval === void 0) { interval = 0; }
            this.type = type;
            if (type == Const.VERTICAL) {
                var angle = -90;
                this.skinBar.x = this.skinValue.height >> 1;
            }
            else {
                var angle = 0;
                this.skinBar.y = this.skinValue.height >> 1;
            }
            this.skinBg.rotation = angle;
            this.skinValue.rotation = angle;
        };
        return SliderBar;
    }(ProgressBar));
    moon.SliderBar = SliderBar;
    __reflect(SliderBar.prototype, "moon.SliderBar", ["moon.ILayout"]);
    /***滚动条 */
    var ScrollBar = (function (_super) {
        __extends(ScrollBar, _super);
        function ScrollBar(bar) {
            if (bar === void 0) { bar = null; }
            var _this = _super.call(this) || this;
            _this.skinBar = bar || Skin.scrollBar;
            _this.skinBar.alpha = 0;
            _this.addChild(_this.skinBar);
            _this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, _this.onTouch, _this);
            _this.touchEnabled = true;
            _this.startPos = new Point;
            _this.stPos = new Point;
            _this.setSize();
            _this.layout();
            return _this;
        }
        ScrollBar.prototype.onTouch = function (e) {
            switch (e.type) {
                case egret.TouchEvent.TOUCH_BEGIN:
                    this.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
                    this.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouch, this);
                    this.stPos.x = e.stageX;
                    this.stPos.y = e.stageY;
                    this.startPos.x = e.stageX - this._target.x;
                    this.startPos.y = e.stageY - this._target.y;
                    this.hideShow(1);
                    this.startTime = egret.getTimer();
                    break;
                case egret.TouchEvent.TOUCH_MOVE:
                    this.moveDo(e.stageX, e.stageY);
                    break;
                case egret.TouchEvent.TOUCH_END:
                    this.stage.removeEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
                    this.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouch, this);
                    this.hideShow(0, 100);
                    this.timeMove(e.stageX, e.stageY);
                    break;
            }
        };
        //缓动动画
        ScrollBar.prototype.timeMove = function (x, y) {
            var time = egret.getTimer() - this.startTime;
            if (time < 500) {
                var target = this._target;
                var maskRect = this.maskRect;
                Tween.removeTweens(target);
                var dx = x - this.stPos.x;
                var dy = y - this.stPos.y;
                var distance = Math.sqrt(dx * dx + dy * dy);
                var value = (distance / time) * 100;
                var tw = Tween.get(target);
                if (this.type == Const.VERTICAL) {
                    var sign = dy > 0 ? 1 : -1;
                    value *= sign;
                    var h = target.y + value;
                    if (h > 0 && target.y + value > 0)
                        h = 0;
                    if (h < 0 && target.y + value < (maskRect.height - target.height))
                        h = maskRect.height - target.height;
                    tw.to({ y: h }, 400, Ease.sineOut).call(this.setBarPos, this);
                }
                else {
                    var sign = dx > 0 ? 1 : -1;
                    value *= sign;
                    var w = target.x + value;
                    if (w > 0 && target.x + value > 0)
                        w = 0;
                    if (w < 0 && target.x + value < (maskRect.width - target.width))
                        w = maskRect.width - target.width;
                    tw.to({ x: w }, 400, Ease.sineOut).call(this.setBarPos, this);
                }
            }
        };
        ScrollBar.prototype.setBarPos = function () {
            if (this.type == Const.VERTICAL)
                this.skinBar.y = -this._target.y / (this._target.height - this.maskRect.height) * (this.maskRect.height - this.skinBar.height);
            else
                this.skinBar.x = -this._target.x / (this._target.width - this.maskRect.width) * (this.maskRect.width - this.skinBar.width);
        };
        ScrollBar.prototype.hideShow = function (alpha, time) {
            if (time === void 0) { time = 1000; }
            Tween.removeTweens(this.skinBar);
            if (alpha == 1) {
                this.skinBar.alpha = 1;
            }
            var tw = Tween.get(this.skinBar);
            tw.to({ alpha: alpha }, time);
        };
        ScrollBar.prototype.moveDo = function (x, y) {
            if (this.type == Const.VERTICAL) {
                this.canMoveY(y);
            }
            else if (this.type == Const.HORIZONTAL) {
                this.canMoveX(x);
            }
        };
        ScrollBar.prototype.canMoveX = function (x) {
            var dis = this.maskRect.width - this._target.width;
            var xx = x - this.startPos.x;
            if (xx > dis && xx < 0) {
                this._target.x = xx;
                this.skinBar.x = -xx / (this._target.width - this.maskRect.width) * (this.maskRect.width - this.skinBar.width);
            }
        };
        ScrollBar.prototype.canMoveY = function (y) {
            var dis = this.maskRect.height - this._target.height;
            var yy = y - this.startPos.y;
            if (yy > dis && yy < 0) {
                this._target.y = yy;
                this.skinBar.y = -yy / (this._target.height - this.maskRect.height) * (this.maskRect.height - this.skinBar.height);
            }
        };
        ScrollBar.prototype.setMask = function () {
            if (this.maskRect != null && this._target != null) {
                this._target.mask = this.maskRect;
            }
        };
        ScrollBar.prototype.setSkinBarPos = function () {
            this.skinBar.x = this.skinBar.y = 0;
            if (this.type == Const.VERTICAL) {
                this.skinBar.x = this.maskRect.width - this.skinBar.width;
            }
            else if (this.type == Const.HORIZONTAL) {
                this.skinBar.y = this.maskRect.height - this.skinBar.height;
            }
        };
        ScrollBar.prototype.layout = function (type, interval) {
            if (type === void 0) { type = Const.VERTICAL; }
            if (interval === void 0) { interval = 0; }
            this.type = type;
            this.setSkinBarPos();
        };
        ScrollBar.prototype.setSize = function (w, h) {
            if (w === void 0) { w = 200; }
            if (h === void 0) { h = 200; }
            this.maskRect = MoonUI.getRect(w, h);
            this.addChild(this.maskRect);
            this.setMask();
            this.setSkinBarPos();
        };
        Object.defineProperty(ScrollBar.prototype, "target", {
            set: function (value) {
                this._target = value;
                this.addChildAt(this._target, 0);
                this.setMask();
            },
            enumerable: true,
            configurable: true
        });
        return ScrollBar;
    }(MoonContainer));
    moon.ScrollBar = ScrollBar;
    __reflect(ScrollBar.prototype, "moon.ScrollBar", ["moon.ILayout"]);
    /**复选框按钮 */
    var CheckBoxBar = (function (_super) {
        __extends(CheckBoxBar, _super);
        function CheckBoxBar() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        CheckBoxBar.prototype.addItemLabel = function (label, item) {
            if (item === void 0) { item = null; }
            if (item == null)
                item = Skin.getCheckBox(label);
            else
                item.label = label;
            this.addItem(item);
        };
        CheckBoxBar.prototype.addItem = function (item) {
            _super.prototype.addItem.call(this, item);
            item.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
            this.addChild(item);
        };
        CheckBoxBar.prototype.removeItem = function (item) {
            _super.prototype.removeItem.call(this, item);
            item.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
            item.removeFromParent(true);
        };
        CheckBoxBar.prototype.onClick = function (e) {
            var item = e.currentTarget;
            this.dispEvent(moon.MoonEvent.CHANGE);
        };
        /**布局 type类型为横或竖，interval为对象间的间隔*/
        CheckBoxBar.prototype.layout = function (type, interval) {
            if (type === void 0) { type = Const.VERTICAL; }
            if (interval === void 0) { interval = 10; }
            for (var i = 0; i < this.items.length; i++) {
                var item = this.items[i];
                if (type == Const.VERTICAL)
                    item.y = (item.height + interval) * i;
                else
                    item.x = (item.width + interval) * i;
            }
        };
        Object.defineProperty(CheckBoxBar.prototype, "selectIndexs", {
            get: function () {
                var nums = [];
                for (var i = 0; i < this.items.length; i++) {
                    var btn = this.items[i];
                    if (btn.currentPage == 1)
                        nums.push(i);
                }
                return nums;
            },
            enumerable: true,
            configurable: true
        });
        return CheckBoxBar;
    }(BasicBar));
    moon.CheckBoxBar = CheckBoxBar;
    __reflect(CheckBoxBar.prototype, "moon.CheckBoxBar", ["moon.ILayout"]);
    /**复选框按钮 */
    var TabbarBar = (function (_super) {
        __extends(TabbarBar, _super);
        function TabbarBar() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this._selectIndex = 0;
            return _this;
        }
        TabbarBar.prototype.onClick = function (e) {
            var curr = e.currentTarget;
            this.selectItem(curr);
        };
        TabbarBar.prototype.selectItem = function (curr) {
            this.reset();
            while (this.hasItem(this.index)) {
                var item = this.getNextItem();
                item.currentPage = 0;
                item.setSkinNormal();
                item.open();
            }
            curr.close();
            curr.currentPage = 1;
            curr.setSkinNormal();
            this._selectIndex = this.items.indexOf(curr);
            this.dispEvent(moon.MoonEvent.CHANGE, this._selectIndex);
        };
        Object.defineProperty(TabbarBar.prototype, "selectIndex", {
            get: function () { return this._selectIndex; },
            set: function (value) { this._selectIndex = value, this.selectItem(this.getItem(value)); },
            enumerable: true,
            configurable: true
        });
        return TabbarBar;
    }(CheckBoxBar));
    moon.TabbarBar = TabbarBar;
    __reflect(TabbarBar.prototype, "moon.TabbarBar");
    /**单选框按钮 */
    var RadioButtonBar = (function (_super) {
        __extends(RadioButtonBar, _super);
        function RadioButtonBar() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.isAutoLayout = false;
            return _this;
        }
        RadioButtonBar.prototype.addItemLabel = function (label, item) {
            if (item === void 0) { item = null; }
            if (item == null)
                item = Skin.getRodatioButton(label);
            else
                item.label = label;
            this.addItem(item);
        };
        RadioButtonBar.prototype.render = function () {
            this.update();
        };
        RadioButtonBar.prototype.update = function () {
            var item;
            if (this.isAutoLayout == true) {
                for (var i = 0; i < this.items.length; i++) {
                    item = this.items[i];
                    item.x = (item.width + 10) * i;
                }
            }
        };
        RadioButtonBar.prototype.onClick = function (e) {
            var item = e.currentTarget;
            this.selectIndex = this.items.indexOf(item);
            this.dispEvent(moon.MoonEvent.CHANGE);
        };
        Object.defineProperty(RadioButtonBar.prototype, "selectIndex", {
            get: function () {
                return this._selectIndex;
            },
            set: function (index) {
                this._selectIndex = index;
                var item = this.items[index];
                this.items.map(setSkinNormal, this);
                function setSkinNormal(i) {
                    i.setSkinNormal();
                }
                item.setSkinDown();
            },
            enumerable: true,
            configurable: true
        });
        return RadioButtonBar;
    }(CheckBoxBar));
    moon.RadioButtonBar = RadioButtonBar;
    __reflect(RadioButtonBar.prototype, "moon.RadioButtonBar");
    /**提示警告框 手动关闭*/
    var AlertBar = (function (_super) {
        __extends(AlertBar, _super);
        function AlertBar(title) {
            if (title === void 0) { title = "提示或警告"; }
            var _this = _super.call(this) || this;
            _this.bgColor = Color.black;
            _this.text = (new Label).textField;
            _this.text.text = title;
            return _this;
        }
        /**加载到舞台之后调用 */
        AlertBar.prototype.render = function () {
            _super.prototype.render.call(this);
            this.initView();
        };
        AlertBar.prototype.initView = function () {
            var node = this.createBackground(0, 0.3);
            var tw = this.text.width;
            var th = this.text.height;
            var w = tw + 80;
            var h = th + 120;
            var x = (this.stageWidth - w) >> 1;
            var y = (this.stageHeight - h) >> 1;
            this.bg = new MoonDisplayObject;
            this.bg.type = Const.SHAPE_RECT_ROUND;
            this.bg.data = { w: w, h: h, c: this.bgColor, ew: 10, eh: 10 };
            this.bg.setBackground(0, 2);
            this.bg.x = x;
            this.bg.y = y;
            this.addChild(this.bg);
            var btn = new BasicButton;
            btn.label = "确 定";
            this.bg.addChild(btn);
            btn.x = (w - btn.width) >> 1;
            btn.y = this.text.y + th + 40;
            btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
            this.text.x = x + ((w - tw) >> 1);
            this.text.y = y + 20;
            this.addChild(this.text);
        };
        AlertBar.prototype.onClick = function (e) {
            this.removeFromParent(true);
            this.dispEvent(MoonEvent.CLOSE);
        };
        Object.defineProperty(AlertBar.prototype, "color", {
            /**设置背景色 */
            set: function (value) {
                this.bgColor = value;
                if (this.bg)
                    this.bg.color = value;
            },
            enumerable: true,
            configurable: true
        });
        ;
        AlertBar.prototype.dispose = function () {
            _super.prototype.dispose.call(this);
            this.bg = null;
            this.bgColor = null;
            this.text = null;
        };
        return AlertBar;
    }(BasicBar));
    moon.AlertBar = AlertBar;
    __reflect(AlertBar.prototype, "moon.AlertBar");
    /**提示警告框 自动关闭*/
    var AlertAutoBar = (function (_super) {
        __extends(AlertAutoBar, _super);
        function AlertAutoBar(title, closeTime) {
            if (title === void 0) { title = "提示或警告"; }
            if (closeTime === void 0) { closeTime = 3; }
            var _this = _super.call(this, title) || this;
            _this.time = closeTime;
            return _this;
        }
        AlertAutoBar.prototype.initView = function () {
            var tw = this.text.width;
            var th = this.text.height;
            var w = tw + 20;
            var h = th + 20;
            var x = (this.stageWidth - w) >> 1;
            var y = (this.stageHeight - h) >> 1;
            this.bg = new MoonDisplayObject;
            this.bg.type = Const.SHAPE_RECT_ROUND;
            this.bg.data = { w: w, h: h, c: this.bgColor, ew: 10, eh: 10 };
            this.bg.setBackground(0, 2);
            this.bg.x = x;
            this.bg.y = y;
            this.addChild(this.bg);
            this.text.x = x + ((w - tw) >> 1);
            this.text.y = y + ((h - th) >> 1);
            this.addChild(this.text);
            this.alpha = 0;
            var ty = this.y - 50;
            Tween.get(this).to({ alpha: 1 }, 500).wait(this.time * 1000).to({ alpha: 0, y: ty }, 500).call(this.backCall, this);
        };
        AlertAutoBar.prototype.backCall = function () {
            Tween.removeTweens(this);
            this.removeFromParent(true);
            this.time = null;
            this.dispEvent(MoonEvent.CLOSE);
        };
        return AlertAutoBar;
    }(AlertBar));
    moon.AlertAutoBar = AlertAutoBar;
    __reflect(AlertAutoBar.prototype, "moon.AlertAutoBar");
    /**提示警告框 滚动显示*/
    var AlertRollBar = (function (_super) {
        __extends(AlertRollBar, _super);
        function AlertRollBar(title, bgWidth) {
            if (title === void 0) { title = "提示或警告"; }
            if (bgWidth === void 0) { bgWidth = 200; }
            var _this = _super.call(this, title) || this;
            _this.bgWidth = bgWidth;
            return _this;
        }
        AlertRollBar.prototype.initView = function () {
            var tw = this.text.width;
            var th = this.text.height;
            var w = this.bgWidth;
            var h = th + 20;
            var x = (this.stageWidth - w) >> 1;
            var y = 100;
            this.bg = new MoonDisplayObject;
            this.bg.type = Const.SHAPE_RECT;
            this.bg.data = { w: w, h: h, c: this.bgColor };
            this.bg.x = x;
            this.bg.y = y;
            this.addChild(this.bg);
            var mask = MoonUI.getRect(w, h, 0, x, y);
            this.bg.mask = mask;
            this.text.x = w;
            this.text.y = 10;
            this.bg.addChild(this.text);
            var time = 2000 + this.text.text.length * 100;
            var tx = -tw;
            Tween.get(this.text).to({ x: tx }, time).call(this.backCall, this);
        };
        AlertRollBar.prototype.backCall = function () {
            Tween.removeTweens(this);
            Tween.removeTweens(this.text);
            this.removeFromParent(true);
            this.bgWidth = null;
            this.dispEvent(MoonEvent.CLOSE);
        };
        return AlertRollBar;
    }(AlertBar));
    moon.AlertRollBar = AlertRollBar;
    __reflect(AlertRollBar.prototype, "moon.AlertRollBar");
    /**输入框 */
    var InputBar = (function (_super) {
        __extends(InputBar, _super);
        function InputBar(width, height) {
            if (width === void 0) { width = 100; }
            if (height === void 0) { height = 50; }
            var _this = _super.call(this) || this;
            _this.text = (new Label).textField;
            _this.inputW = width;
            _this.inputH = height;
            return _this;
        }
        /**加载到舞台之后调用 */
        InputBar.prototype.render = function () {
            _super.prototype.render.call(this);
            var w = this.inputW;
            var h = this.inputH;
            this.bg = new MoonDisplayObject;
            this.bg.type = Const.SHAPE_RECT_ROUND;
            this.bg.data = { w: w, h: h, c: this.bgColor, ew: 10, eh: 10 };
            this.bg.setBackground(0, 2);
            this.addChild(this.bg);
            var side = 5;
            this.text.x = side;
            this.text.y = side;
            this.text.width = w - side * 2;
            this.text.height = h - side * 2;
            this.text.type = egret.TextFieldType.INPUT;
            this.addChild(this.text);
        };
        /**设置为多行 */
        InputBar.prototype.setMultiline = function () {
            this.text.wordWrap = true;
            this.text.multiline = true;
            this.text.verticalAlign = egret.VerticalAlign.TOP;
        };
        Object.defineProperty(InputBar.prototype, "color", {
            /**设置背景色 */
            set: function (value) {
                this.bgColor = value;
                if (this.bg)
                    this.bg.color = value;
            },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(InputBar.prototype, "maxChars", {
            /**设置最大数量 */
            set: function (value) { this.text.maxChars = value; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(InputBar.prototype, "restrict", {
            /**设置输入内容限制（如只输入字母数字 a-zA-Z0-9） */
            set: function (value) { this.text.restrict = value; },
            enumerable: true,
            configurable: true
        });
        return InputBar;
    }(BasicBar));
    moon.InputBar = InputBar;
    __reflect(InputBar.prototype, "moon.InputBar");
    /**面板 */
    var PanelBar = (function (_super) {
        __extends(PanelBar, _super);
        function PanelBar(pWidth, pHeight) {
            if (pWidth === void 0) { pWidth = 0; }
            if (pHeight === void 0) { pHeight = 0; }
            var _this = _super.call(this) || this;
            _this.titleHeight = 60;
            _this.pWidth = pWidth;
            _this.pHeight = pWidth;
            _this.titleBg = new Sprite;
            _this.containerBg = new Sprite;
            _this.title = (new Label).textField;
            _this.container = new MoonContainer;
            return _this;
        }
        /**加载到舞台之后调用 */
        PanelBar.prototype.render = function () {
            if (this.pWidth == 0 && this.pWidth == 0) {
                _super.prototype.render.call(this);
            }
            else {
                this.stageWidth = this.pWidth;
                this.stageHeight = this.pHeight;
            }
            this.createRectBySprite(this.titleBg, this.stageWidth, this.titleHeight, moon.Color.titleBackground);
            this.createRectBySprite(this.containerBg, this.stageWidth, this.stageHeight - this.titleHeight, moon.Color.white, 0, this.titleHeight);
            this.addChild(this.titleBg);
            this.addChild(this.containerBg);
            this.title.anchorOffsetX = this.title.textWidth >> 1;
            this.title.anchorOffsetY = this.title.textHeight >> 1;
            this.title.x = this.stageWidth >> 1;
            this.title.y = this.titleHeight >> 1;
            this.addChild(this.title);
            this.container.y = this.titleHeight;
            this.addChild(this.container);
            this.containerMask = this.createRect(this.stageWidth, this.stageHeight - this.titleHeight, moon.Color.white, 0, this.titleHeight);
            this.container.mask = this.containerMask;
            this.touchEnabled = true; //为了阻挡面板下所有事件
            this.dispEvent(MoonEvent.RENDER_COMPLETE);
        };
        PanelBar.prototype.addItem = function (item, x, y) {
            if (x === void 0) { x = 0; }
            if (y === void 0) { y = 0; }
            _super.prototype.addItem.call(this, item);
            if (x != 0)
                item.x = x;
            if (y != 0)
                item.y = y;
            this.container.addChild(item);
        };
        PanelBar.prototype.removeItem = function (item) {
            _super.prototype.removeItem.call(this, item);
            if (this.container.contains(item))
                this.container.removeChild(item);
        };
        Object.defineProperty(PanelBar.prototype, "label", {
            get: function () {
                return this.title.text;
            },
            set: function (value) {
                this.title.text = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PanelBar.prototype, "colorTop", {
            set: function (c) {
                var w = this.titleBg.width, h = this.titleBg.height;
                this.createRectBySprite(this.titleBg, w, h, c);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PanelBar.prototype, "colorBottom", {
            set: function (c) {
                var w = this.containerBg.width, h = this.containerBg.height;
                this.createRectBySprite(this.containerBg, w, h, c, 0, this.titleHeight);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PanelBar.prototype, "windowRect", {
            get: function () {
                var rect = new Rectangle(0, 0, this.stageWidth, this.stageHeight);
                return rect;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PanelBar.prototype, "topHeight", {
            get: function () {
                return this.titleHeight;
            },
            enumerable: true,
            configurable: true
        });
        PanelBar.prototype.removeAll = function () {
            this.container.dispose();
        };
        return PanelBar;
    }(BasicBar));
    moon.PanelBar = PanelBar;
    __reflect(PanelBar.prototype, "moon.PanelBar");
    /**多个面板管理 */
    var PanelMoreManager = (function (_super) {
        __extends(PanelMoreManager, _super);
        function PanelMoreManager() {
            var _this = _super.call(this) || this;
            _this.radioButton = new RadioButtonBar;
            _this.currentPage = 0;
            _this.posStartX = 0;
            _this.moveItems = [];
            _this.container = new MoonContainer;
            _this.addChild(_this.container);
            _this.radioButton.isAutoLayout = true;
            return _this;
        }
        PanelMoreManager.prototype.open = function () {
            this.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouch, this);
        };
        PanelMoreManager.prototype.close = function () {
            this.stage.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouch, this);
        };
        PanelMoreManager.prototype.update = function () {
            this.container.removeChildren();
            var itemW;
            var itemH;
            if (this.items.length > 0) {
                var item = this.items[0];
                this.container.addChild(item);
                itemW = item.windowRect.width;
                itemH = item.windowRect.height;
                this.panelWidth = itemW;
            }
            var len = this.items.length;
            for (var i = 0; i < len; i++) {
                var btn = new BasicButton(moon.Skin.pointNormal, moon.Skin.pointDown);
                this.radioButton.addItem(btn);
            }
            btn = this.radioButton.getItem(0);
            btn.setSkinDown();
            this.radioButton.x = (itemW - len * 22) >> 1;
            this.radioButton.y = itemH - 20;
            this.addChild(this.radioButton);
        };
        PanelMoreManager.prototype.render = function () {
            this.update();
            if (this.items.length > 1) {
                this.open();
            }
        };
        PanelMoreManager.prototype.onTouch = function (e) {
            switch (e.type) {
                case egret.TouchEvent.TOUCH_BEGIN:
                    this.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
                    this.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouch, this);
                    this.posStartX = e.stageX;
                    this.dispEvent(MoonEvent.START);
                    break;
                case egret.TouchEvent.TOUCH_MOVE:
                    this.moveDo(e.stageX);
                    break;
                case egret.TouchEvent.TOUCH_END:
                    this.stage.removeEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
                    this.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouch, this);
                    this.moveEnd(e.stageX);
                    break;
            }
        };
        PanelMoreManager.prototype.moveDo = function (x) {
            var disx = x - this.posStartX;
            if (Math.abs(disx) > 20) {
                if (this.moveItems.length == 0) {
                    var item = this.items[this.currentPage];
                    var width = this.panelWidth;
                    this.moveItems.push(item);
                    if (this.currentPage == 0) {
                        item = this.items[this.currentPage + 1];
                        this.container.addChild(item);
                        item.x = width;
                        this.moveItems.push(item);
                    }
                    else if (this.currentPage == this.items.length - 1) {
                        item = this.items[this.currentPage - 1];
                        this.container.addChild(item);
                        item.x = -width;
                        this.moveItems.push(item);
                    }
                    else {
                        item = this.items[this.currentPage - 1];
                        this.container.addChild(item);
                        item.x = -width;
                        this.moveItems.push(item);
                        item = this.items[this.currentPage + 1];
                        this.container.addChild(item);
                        item.x = width;
                        this.moveItems.push(item);
                    }
                }
                var boo1 = (this.currentPage == 0 && disx > 0);
                var boo2 = ((this.currentPage == this.items.length - 1) && disx < 0);
                if (!boo1 && !boo2) {
                    this.container.x = disx;
                }
            }
        };
        PanelMoreManager.prototype.moveEnd = function (x) {
            if (this.container.x == 0) {
                this.backCall(0);
                return;
            }
            var disx = x - this.posStartX;
            var tw = egret.Tween.get(this.container);
            var currX = this.panelWidth;
            var turnDis = this.panelWidth >> 2;
            //至少滑动窗口宽的四分之一才可以算翻页
            if (Math.abs(disx) > turnDis) {
                currX = this.panelWidth;
                currX *= disx > 0 ? 1 : -1;
            }
            else {
                disx = 0;
                currX = 0;
            }
            var time = 200;
            tw.to({ x: currX }, time);
            tw.call(this.backCall, this, [disx]);
        };
        /**结束翻页后的回调函数 */
        PanelMoreManager.prototype.backCall = function (disx) {
            if (disx > 0) {
                this.currentPage--;
                this.currentPage = this.currentPage < 0 ? 0 : this.currentPage;
            }
            else if (disx < 0) {
                this.currentPage++;
                this.currentPage = this.currentPage == this.items.length ? this.items.length - 1 : this.currentPage;
            }
            this.container.removeChildren();
            var item = this.items[this.currentPage];
            item.x = 0;
            this.container.addChild(item);
            this.radioButton.selectIndex = this.currentPage;
            this.moveItems.length = 0;
            this.container.x = 0;
            this.dispEvent(MoonEvent.OVER);
        };
        /**销毁*/
        PanelMoreManager.prototype.dispose = function () {
            _super.prototype.dispose.call(this);
            this.close();
        };
        return PanelMoreManager;
    }(BasicBar));
    moon.PanelMoreManager = PanelMoreManager;
    __reflect(PanelMoreManager.prototype, "moon.PanelMoreManager", ["moon.IOnoff"]);
    var GameData = (function () {
        function GameData() {
        }
        /**游戏屏幕宽 */
        GameData.stageWidth = 640;
        /**游戏屏幕高 */
        GameData.stageHeight = 1136;
        /**帧频*/
        GameData.FPS = 60;
        /**游戏版号，默认是调试版 */
        GameData.version = Const.VER_DEBUG;
        /**是否为移动模式（例如移动电话或平板电脑） */
        GameData.isMobile = egret.Capabilities.isMobile;
        /**游戏的ID */
        GameData.gameId = 1;
        /**游戏分数 */
        GameData.score = 0;
        /**游戏历史分数 */
        GameData.scoreHighest = 0;
        return GameData;
    }());
    moon.GameData = GameData;
    __reflect(GameData.prototype, "moon.GameData");
    /**游戏加载模版 */
    var GameLoad = (function (_super) {
        __extends(GameLoad, _super);
        function GameLoad() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.color = 0XF9AB03;
            return _this;
        }
        GameLoad.prototype.render = function () {
            _super.prototype.render.call(this);
            this.createBgGradientFill();
            var container = new Sprite;
            this.addChild(container);
            var sw = this.stageWidth;
            var sh = this.stageHeight;
            var w = 80;
            var loadbg = MoonUI.getRoundRect(sw - 100, w, 0XFCE59D, 10, 10);
            loadbg.x = (sw - loadbg.width) >> 1;
            loadbg.y = (sh - loadbg.height) >> 1;
            container.addChild(loadbg);
            //--------
            var progress = MoonUI.getRect(sw - 120, w - 10, this.color);
            progress.x = (sw - progress.width) >> 1;
            progress.y = (sh - progress.height) >> 1;
            container.addChild(progress);
            this.proWidth = progress.width;
            var mask = MoonUI.getRoundRect(sw - 120, w - 10, 0, 10, 10);
            mask.x = (sw - mask.width) >> 1;
            mask.y = (sh - mask.height) >> 1;
            progress.mask = mask;
            this.progress = progress;
            //--------
            var txtbg = new MoonDisplayObject();
            txtbg.type = moon.Const.SHAPE_CIRCLE;
            txtbg.data = { r: w / 2, c: 0XE18E0D };
            txtbg.setBackground(0XFFFFFF, 5);
            this.addChild(txtbg);
            txtbg.x = loadbg.x + loadbg.width - w / 2;
            txtbg.y = loadbg.y + w / 2;
            this.txtLoadPos = new Point(txtbg.x, txtbg.y);
            var txtExp = this.createText(0, 0, "");
            txtExp.size = 40;
            txtExp.textColor = 0xB07300;
            this.txtLoad = txtExp;
            //--------
            var txtTip = this.createText(0, 0, "游戏加载");
            txtTip.size = 40;
            txtTip.x = (sw - txtTip.width) >> 1;
            txtTip.y = loadbg.y - txtTip.height * 2;
            var txtName = this.createText(0, 0, "");
            txtName.size = 40;
            this.txtName = txtName;
            this.updateName("敬请期待");
            //--------
            this.createAirFan();
            this.airFan.x = txtbg.x;
            this.airFan.y = txtbg.y;
            this.createLogo();
            this.update(0);
            this.play();
        };
        GameLoad.prototype.loop = function (n) {
            this.airFan.rotation += 3;
            return true;
        };
        GameLoad.prototype.createAirFan = function () {
            this.airFan = new Sprite;
            this.addChild(this.airFan);
            for (var i = 0; i < 4; i++) {
                var shape = new Sprite();
                this.airFan.addChild(shape);
                shape.graphics.lineStyle(0);
                shape.graphics.beginFill(0xFFFFFF);
                shape.graphics.cubicCurveTo(-29, -28, 29, -28, 0, 0);
                shape.graphics.endFill();
                shape.rotation = i * 90;
            }
        };
        GameLoad.prototype.createLogo = function () {
            var sw = this.stageWidth;
            var sh = this.stageHeight;
            var logo = new MoonDisplayObject();
            logo.type = moon.Const.SHAPE_CIRCLE;
            logo.data = { r: 50, c: 0XE18E0D };
            logo.setBackground(0XFFFFFF, 2);
            logo.x = sw >> 1;
            logo.y = logo.height;
            this.addChild(logo);
            var txtName = this.createText(0, 0, "ZL");
            txtName.size = 40;
            txtName.x = logo.x - (txtName.width >> 1);
            txtName.y = logo.y - (txtName.height >> 1) - 15;
            txtName = this.createText(0, 0, "game");
            txtName.size = 30;
            txtName.x = logo.x - (txtName.width >> 1);
            txtName.y = logo.y - (txtName.height >> 1) + 15;
            this.addChild(moon.MoonUI.getHeart(15, 0XFFFFFF));
            txtName = this.createText(0, 0, "子乐游戏");
            txtName.size = 40;
            txtName.textColor = 0XE09F21;
            txtName.x = sw - txtName.width - 10;
            txtName.y = sh - txtName.height - 10;
        };
        /**创建渐变色背景 */
        GameLoad.prototype.createBgGradientFill = function (c1, c2) {
            if (c1 === void 0) { c1 = 0XFDD559; }
            if (c2 === void 0) { c2 = 0XE09F21; }
            var w = this.stageWidth;
            var h = this.stageHeight;
            var matrix = new egret.Matrix();
            matrix.createGradientBox(w * 2, h * 2, Math.PI / 2);
            var sprite = new Sprite;
            sprite.graphics.beginGradientFill(egret.GradientType.RADIAL, [c1, c2], [1, 1], [0, 255], matrix);
            sprite.graphics.drawRect(0, 0, w, h);
            this.addChild(sprite);
            return sprite;
        };
        GameLoad.prototype.updateName = function (name) {
            this.txtName.text = name;
            this.txtName.x = (this.stageWidth - this.txtName.width) >> 1;
            this.txtName.y = this.stageHeight / 2 + this.txtName.height * 2;
        };
        GameLoad.prototype.update = function (value) {
            if (value > 1)
                return;
            if (value > 0.99)
                this.stop();
            this.progress.scaleX = value;
            var txtExp = this.txtLoad;
            var pos = this.txtLoadPos;
            txtExp.text = Math.ceil(value * 100) + "%";
            txtExp.x = (this.stageWidth - txtExp.width) >> 1;
            txtExp.y = pos.y - txtExp.height / 2;
            var exp = MoonUI.getCircle(5 + Math.random() * 5, this.color, pos.x, pos.y);
            exp.y = 10 - Math.random() * 20;
            this.addChildAt(exp, 2);
            Tween.get(exp).to({ x: -this.proWidth, alpha: 0 }, 1000);
        };
        return GameLoad;
    }(moon.GameView));
    moon.GameLoad = GameLoad;
    __reflect(GameLoad.prototype, "moon.GameLoad");
})(moon || (moon = {}));
var MOON_FTP = 24;
var moon;
(function (moon) {
    /**图像类 */
    var Image = (function (_super) {
        __extends(Image, _super);
        function Image(skinName) {
            if (skinName === void 0) { skinName = ""; }
            var _this = _super.call(this) || this;
            if (skinName != "") {
                _this.skinName = skinName;
                _this.position = new Point();
                _this.addBitmap();
                _this.bgWidth = _this.width;
                _this.bgHeight = _this.height;
            }
            return _this;
        }
        Image.prototype.addBitmap = function () {
            if (RES.hasRes(this.skinName)) {
                this.skinImage = new moon.Scale9Image(this.skinName);
                this.skinImage.smoothing = true;
                this.addChild(this.skinImage);
            }
            else {
                trace("找不到资源：" + this.skinName);
                //egret.error("找不到key"+this.skinName);
            }
        };
        /**设置锚点在中心 */
        Image.prototype.setAnchorCenter = function () {
            this.anchorOffsetX = this.width >> 1;
            this.anchorOffsetY = this.height >> 1;
        };
        return Image;
    }(moon.MoonContainer));
    moon.Image = Image;
    __reflect(Image.prototype, "moon.Image");
    /**图像容器类 */
    var BasicContainer = (function (_super) {
        __extends(BasicContainer, _super);
        function BasicContainer() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.items = [];
            _this.index = 0;
            return _this;
        }
        BasicContainer.prototype.addItem = function (item) {
            this.items.push(item);
        };
        BasicContainer.prototype.removeItem = function (index) {
            if (this.hasItem(index)) {
                this.items.splice(index, 1);
            }
        };
        BasicContainer.prototype.getItem = function (index) {
            return this.items[index];
        };
        BasicContainer.prototype.hasItem = function (index) {
            return this.items.length > 0 && (index >= 0 && index < this.items.length);
        };
        BasicContainer.prototype.getNextItem = function () {
            return this.items[this.index++];
        };
        BasicContainer.prototype.reset = function () {
            this.index = 0;
        };
        return BasicContainer;
    }(Image));
    moon.BasicContainer = BasicContainer;
    __reflect(BasicContainer.prototype, "moon.BasicContainer");
    /**图像贴图类 */
    var ImageChartlet = (function (_super) {
        __extends(ImageChartlet, _super);
        function ImageChartlet(skinName, count) {
            if (count === void 0) { count = 1; }
            var _this = _super.call(this) || this;
            _this.skinName = skinName;
            for (var i = 0; i < count; i++) {
                _this.items.push(_this.getBitmap());
            }
            return _this;
        }
        ImageChartlet.prototype.getBitmap = function () {
            var skin;
            if (RES.hasRes(this.skinName)) {
                skin = new moon.Scale9Image(this.skinName);
                this.addChild(skin);
            }
            else {
                trace("找不到资源：" + this.skinName);
            }
            return skin;
        };
        /**竖排获横排 */
        ImageChartlet.prototype.layout = function (type, interval) {
            if (interval === void 0) { interval = 0; }
            if (type == moon.Const.VERTICAL)
                moon.SimpleLayout.displayRank(this.items, 1, interval, interval, 0, 0);
            else if (type == moon.Const.HORIZONTAL)
                moon.SimpleLayout.displayRank(this.items, this.items.length, interval, interval, 0, 0);
        };
        /**多行排列，xNum是一排排几个 */
        ImageChartlet.prototype.setMultiLine = function (xNum, interval) {
            if (interval === void 0) { interval = 0; }
            moon.SimpleLayout.displayRank(this.items, xNum, interval, interval, 0, 0);
        };
        return ImageChartlet;
    }(BasicContainer));
    moon.ImageChartlet = ImageChartlet;
    __reflect(ImageChartlet.prototype, "moon.ImageChartlet", ["moon.ILayout"]);
    /**图像动画类 */
    var ImageAnimation = (function (_super) {
        __extends(ImageAnimation, _super);
        function ImageAnimation(skinName, start, end, type) {
            if (skinName === void 0) { skinName = ""; }
            if (type === void 0) { type = "png"; }
            var _this = _super.call(this) || this;
            _this._ftp = MOON_FTP;
            for (var i = start; i <= end; i++) {
                _this.items.push(skinName + i + "_" + type);
            }
            _this.skinName = _this.getItem(0);
            _this.addBitmap();
            _this.createTime();
            return _this;
        }
        ImageAnimation.prototype.createTime = function () {
            if (this.timer == null) {
                this.timer = new egret.Timer(1000 / this.ftp, 0);
                this.timer.addEventListener(egret.TimerEvent.TIMER, this.onTimer, this);
            }
        };
        ImageAnimation.prototype.onTimer = function () {
            if (this.hasItem(++this.index)) {
                this.gotoAndStop(this.index);
            }
            else {
                if (this.loop) {
                    this.reset();
                    this.gotoAndStop(this.index);
                }
                else {
                    this.timer.stop();
                }
            }
        };
        ImageAnimation.prototype.gotoAndStop = function (index) {
            if (this.hasItem(index)) {
                this.index = index;
                this.skinName = this.getItem(index);
                this.update();
            }
            else {
                trace("gotoAndStop的参数请保持在0到" + this.items.length, "当前index=" + index);
            }
        };
        ImageAnimation.prototype.gotoAndPlay = function (index) {
            this.index = index;
            this.play();
        };
        ImageAnimation.prototype.play = function () {
            this.timer.start();
        };
        ImageAnimation.prototype.stop = function () {
            this.timer.stop();
        };
        ImageAnimation.prototype.update = function () {
            if (RES.hasRes(this.skinName)) {
                this.skinImage.texture = RES.getRes(this.skinName);
            }
            else {
                trace("找不到资源：" + this.skinName);
            }
        };
        Object.defineProperty(ImageAnimation.prototype, "currentFrame", {
            get: function () { return this.index; },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ImageAnimation.prototype, "ftp", {
            get: function () { return this._ftp; },
            set: function (value) {
                this._ftp = value;
                this.removeTime();
                this.createTime();
            },
            enumerable: true,
            configurable: true
        });
        ImageAnimation.prototype.removeTime = function () {
            if (this.timer != null) {
                this.timer.stop();
                this.timer.removeEventListener(egret.TimerEvent.TIMER, this.onTimer, this);
                this.timer = null;
            }
        };
        ImageAnimation.prototype.dispose = function () {
            _super.prototype.dispose.call(this);
            this.removeTime();
        };
        return ImageAnimation;
    }(BasicContainer));
    moon.ImageAnimation = ImageAnimation;
    __reflect(ImageAnimation.prototype, "moon.ImageAnimation");
    /**图像布局类 */
    var ImageLayout = (function () {
        function ImageLayout() {
        }
        ImageLayout.getIns = function () {
            if (this.instance == null)
                this.instance = new ImageLayout();
            return this.instance;
        };
        ImageLayout.prototype.setImage = function (image) {
            this.image = image;
        };
        ImageLayout.prototype.setStageWH = function (w, h) {
            this.tw = w;
            this.th = h;
        };
        ImageLayout.prototype.setTop = function (distance) {
            this.image.y = distance;
        };
        ImageLayout.prototype.setBottom = function (distance) {
            this.image.y = this.th - this.image.height - distance;
        };
        ImageLayout.prototype.setLeft = function (distance) {
            this.image.x = distance;
        };
        ImageLayout.prototype.setRight = function (distance) {
            this.image.x = this.tw - this.image.width - distance;
        };
        ImageLayout.prototype.setCenterX = function (distance) {
            if (distance === void 0) { distance = 0; }
            this.image.x = ((this.tw - this.image.width) >> 1) + distance;
        };
        ImageLayout.prototype.setCenterY = function (distance) {
            if (distance === void 0) { distance = 0; }
            this.image.y = ((this.tw - this.image.width) >> 1) + distance;
        };
        ImageLayout.prototype.setCenterXByPanent = function (image) {
            if (image.parent instanceof Image)
                image.x = (image.parent.bgWidth - image.width) >> 1;
            else
                image.x = (image.parent.width - image.width) >> 1;
        };
        ImageLayout.prototype.setCenterYByPanent = function (image) {
            if (image.parent instanceof Image)
                image.y = (image.parent.bgHeight - image.height) >> 1;
            else
                image.y = (image.parent.height - image.height) >> 1;
        };
        return ImageLayout;
    }());
    moon.ImageLayout = ImageLayout;
    __reflect(ImageLayout.prototype, "moon.ImageLayout");
})(moon || (moon = {}));
//子弹基础类
//1.生成子弹图片
//2.更换子弹的刚体
//3.负责子弹的移动，或者给力
//4.负责子弹的停止
var py2Obj;
(function (py2Obj) {
    var basicObj = (function () {
        function basicObj(world, gamePanle, romveSkins) {
            this.m_removeSkins = []; //需要删除刚体的皮肤
            this.m_world = world;
            this.m_gamePanle = gamePanle;
            this.m_removeSkins = romveSkins;
        }
        basicObj.prototype.getBody = function () {
            return this.m_body;
        };
        /**设置初始化 */
        basicObj.prototype.init = function () {
            this.m_body = this.createMyRigidbody();
        };
        /**设置材质 */
        basicObj.prototype.setMaterial = function (material) {
            this.m_body.shapes[0].material = material;
            var roleAndStoneMaterial = new p2.ContactMaterial(material, material, { restitution: 2, friction: 5 }); //弹性，摩擦力
            this.m_world.p2World.addContactMaterial(roleAndStoneMaterial);
        };
        /**设置位置 */
        basicObj.prototype.setPostion = function (x, y) {
            this.m_body.position = [x, y];
        };
        /**设置冲量 */
        basicObj.prototype.setBallImpulse = function () {
            var x = Math.random() > 0.5 ? -5000 : 5000;
            var y = -5000 - (Math.random() * 2000);
            this.setForce(x, y);
        };
        /**设置力 */
        basicObj.prototype.setForce = function (x, y) {
            this.m_body.fixedX = false;
            this.m_body.fixedY = false;
            this.m_body.applyImpulse([x, y], [0, 0]);
        };
        /** 创建皮肤*/
        basicObj.prototype.createSkin = function (name) {
            var skin = new NumImage(name);
            skin.x = -500; //避免在一出现的时候会在左上角闪现
            skin.setAnchorCenter();
            this.m_gamePanle.addChild(skin);
            return skin;
        };
        /**固定我们的球 */
        basicObj.prototype.fixObj = function () {
            this.m_body.fixedX = true;
            this.m_body.fixedY = true;
        };
        basicObj.prototype.remove = function () {
            this.m_removeSkins.push(this.m_body.userData.skin);
            this.m_world.removeBodys.push(this.m_body);
        };
        /** 创建球刚体*/
        basicObj.prototype.createMyRigidbody = function () {
            var world = this.m_world;
            var skin = this.createSkin("ball_png");
            var body = world.createCircleBodyShape(skin.width >> 1);
            body.userData.skin = skin;
            body.userData.data = this;
            body.mass = 0; //质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
            //body.gravityScale=0;
            var shape = body.shapes[0];
            shape.collisionGroup = 2; //010与001为0，010与110为1
            return body;
        };
        basicObj.prototype.getCollision = function (otherBody) {
        };
        return basicObj;
    }());
    py2Obj.basicObj = basicObj;
    __reflect(basicObj.prototype, "py2Obj.basicObj");
})(py2Obj || (py2Obj = {}));
var MButton = (function (_super) {
    __extends(MButton, _super);
    function MButton() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return MButton;
}(moon.BasicButton));
__reflect(MButton.prototype, "MButton");
;
var MImage = (function (_super) {
    __extends(MImage, _super);
    function MImage() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return MImage;
}(moon.Image));
__reflect(MImage.prototype, "MImage");
;
var ImageAnimation = (function (_super) {
    __extends(ImageAnimation, _super);
    function ImageAnimation() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return ImageAnimation;
}(moon.ImageAnimation));
__reflect(ImageAnimation.prototype, "ImageAnimation");
;
var Layout = (function (_super) {
    __extends(Layout, _super);
    function Layout() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Layout;
}(moon.ImageLayout));
__reflect(Layout.prototype, "Layout");
;
var Scale9Image = (function (_super) {
    __extends(Scale9Image, _super);
    function Scale9Image() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Scale9Image;
}(moon.Scale9Image));
__reflect(Scale9Image.prototype, "Scale9Image");
;
var MoonEvent = (function (_super) {
    __extends(MoonEvent, _super);
    function MoonEvent() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return MoonEvent;
}(moon.MoonEvent));
__reflect(MoonEvent.prototype, "MoonEvent");
;
var GameData = (function (_super) {
    __extends(GameData, _super);
    function GameData() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return GameData;
}(moon.GameData));
__reflect(GameData.prototype, "GameData");
;
var Const = (function (_super) {
    __extends(Const, _super);
    function Const() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return Const;
}(moon.Const));
__reflect(Const.prototype, "Const");
;
var moon;
(function (moon) {
    /**游戏模版 */
    var BasicGameMain = (function (_super) {
        __extends(BasicGameMain, _super);
        function BasicGameMain() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        /**加载到舞台之后调用 */
        BasicGameMain.prototype.render = function () {
            _super.prototype.render.call(this);
            this.initView();
        };
        BasicGameMain.prototype.initView = function () {
            this.createBgGradientFill();
            this.panelGame = new BasicGamePanel;
            this.panelGame.addEvent(moon.MoonEvent.OVER, this.onOver, this);
            this.addChild(this.panelGame);
            this.setBtn = new SetButton;
            this.setBtn.x = 100;
            this.setBtn.y = 100;
            this.setBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.openSetPanel, this);
            this.addChild(this.setBtn);
            this.panelSet = new BasicGameSet;
            this.panelSet.addEvent(moon.MoonEvent.PLAY, this.onSetHandler, this);
            this.panelSet.addEvent(moon.MoonEvent.CHANGE, this.onSetHandler, this);
            this.panelStart = new BasicGameStart;
            this.panelStart.addEvent(moon.MoonEvent.START, this.start, this);
            this.addChild(this.panelStart);
            this.panelOver = new BasicGameOver;
            this.panelOver.addEvent(moon.MoonEvent.START, this.start, this);
            // this.addChild(this.panelOver);
        };
        BasicGameMain.prototype.start = function (e) {
            this.panelGame.initGame();
            this.panelGame.start();
        };
        BasicGameMain.prototype.onOver = function (e) {
            this.addChild(this.panelOver);
            this.panelOver.alpha = 0;
            Tween.get(this.panelOver).to({ alpha: 1 }, 300);
            this.panelOver.update(e.data);
        };
        BasicGameMain.prototype.openSetPanel = function (e) {
            this.addChild(this.panelSet);
            this.panelSet.alpha = 0;
            Tween.get(this.panelSet).to({ alpha: 1 }, 300);
            this.panelGame.pause();
        };
        BasicGameMain.prototype.onSetHandler = function (e) {
            if (e.type == moon.MoonEvent.PLAY) {
                this.panelGame.start();
            }
            else {
                var value = e.data;
                if (e.dataType == "soundBg") {
                }
                else if (e.dataType == "soundEffect") {
                }
            }
        };
        return BasicGameMain;
    }(moon.GameView));
    moon.BasicGameMain = BasicGameMain;
    __reflect(BasicGameMain.prototype, "moon.BasicGameMain");
    /**游戏模版 */
    var BasicGamePanel = (function (_super) {
        __extends(BasicGamePanel, _super);
        function BasicGamePanel() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.myScore = 0; //个人得分
            _this.time = 0; //倒计时
            return _this;
        }
        /**加载到舞台之后调用 */
        BasicGamePanel.prototype.render = function () {
            _super.prototype.render.call(this);
            this.initView();
        };
        BasicGamePanel.prototype.initView = function () {
            this.createBgGradientFill();
            this.txtMyScore = this.createText();
            this.txtTime = this.createText();
            this.txtLevel = this.createText(200);
            this.txtBlood = this.createText(400);
            this.initGame();
        };
        BasicGamePanel.prototype.initGame = function () {
            this.level = 1;
            this.myScore = 0;
            this.time = 0;
            this.blood = 200;
            this.updateBlood();
            this.updateLevel();
            this.updateScore();
        };
        BasicGamePanel.prototype.start = function () {
            this.play();
        };
        BasicGamePanel.prototype.pause = function () {
            this.stop();
        };
        BasicGamePanel.prototype.loop = function (n) {
            this.blood--;
            this.score += 10;
            this.updateScore();
            this.updateBlood();
            return true;
        };
        BasicGamePanel.prototype.over = function () {
            this.dispEvent(moon.MoonEvent.OVER, { score: this.myScore, level: this.level });
            this.stop();
        };
        BasicGamePanel.prototype.updateLevel = function () {
            this.txtLevel.text = "level:" + this.level;
        };
        BasicGamePanel.prototype.updateScore = function () {
            this.txtScore.text = "score:" + this.score;
        };
        BasicGamePanel.prototype.updateTime = function () {
            this.txtTime.text = "time:" + this.time;
        };
        BasicGamePanel.prototype.updateBlood = function () {
            this.txtBlood.text = "blood:" + this.blood;
            if (this.blood == 0) {
                this.over();
            }
        };
        BasicGamePanel.prototype.createImageBg = function (name) {
            this.addChild(new MImage(name));
        };
        BasicGamePanel.prototype.dispose = function () {
            this.stop();
            _super.prototype.dispose.call(this);
        };
        return BasicGamePanel;
    }(moon.GameView));
    moon.BasicGamePanel = BasicGamePanel;
    __reflect(BasicGamePanel.prototype, "moon.BasicGamePanel");
    /**游戏开始界面 */
    var BasicGameStart = (function (_super) {
        __extends(BasicGameStart, _super);
        function BasicGameStart() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        // protected btnRestartadd: MButton;
        /**加载到舞台之后调用 */
        BasicGameStart.prototype.render = function () {
            _super.prototype.render.call(this);
            this.initView();
        };
        BasicGameStart.prototype.initView = function () {
            var bg = this.createBackground();
            bg.alpha = 0.5;
            this.txtMyScore = this.createText();
            this.initGame();
            this.createBtn("开始游戏");
            this.createTitle("游戏标题");
        };
        BasicGameStart.prototype.initGame = function () {
            this.myScore;
            this.updateScore();
        };
        BasicGameStart.prototype.createBtn = function (value) {
            var btn = this.createButton(value);
            btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
            btn.x = (this.stageWidth - btn.width) >> 1;
            btn.y = (this.stageHeight - btn.height) >> 1;
            return btn;
        };
        BasicGameStart.prototype.createTitle = function (value) {
            var title = this.createText(0, 0, value);
            title.x = (this.stageWidth - title.width) / 2;
            title.y = (this.stageHeight - title.height) / 2 - 100;
            return title;
        };
        BasicGameStart.prototype.onClick = function (e) {
            //     console.log("++++++");
            this.dispEvent(moon.MoonEvent.START);
            Tween.get(this).to({ alpha: 0 }, 300).call(this.backCall, this);
            // this.btnRestartadd.touchEnabled = false;//开始按钮
            // this.removeChild(this.btnRestartadd);
        };
        BasicGameStart.prototype.backCall = function (e) {
            this.removeFromParent();
        };
        BasicGameStart.prototype.createImageBg = function (name) {
            this.addChild(new MImage(name));
        };
        BasicGameStart.prototype.updateScore = function () {
            this.txtScores.text = "score:" + this.score;
        };
        return BasicGameStart;
    }(moon.GameView));
    moon.BasicGameStart = BasicGameStart;
    __reflect(BasicGameStart.prototype, "moon.BasicGameStart");
    /**游戏结束界面 */
    var BasicGameOver = (function (_super) {
        __extends(BasicGameOver, _super);
        function BasicGameOver() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        BasicGameOver.prototype.initView = function () {
            var bg = this.createBackground();
            bg.alpha = 0.5;
            this.btnRestart = this.createBtn("再来一次");
            this.btnRank = this.createBtn("排行榜");
            this.btnRank.y += 100;
            this.txtScore = this.createText();
            this.txtLevel = this.createText();
            this.rankPanel = new BasicGameRank;
        };
        BasicGameOver.prototype.update = function (data) {
            this.txtScore.text = "score:" + data["score"];
            this.txtLevel.text = "level:" + data["level"];
            this.txtScore.x = (this.stageWidth - this.txtScore.width) / 2;
            this.txtLevel.x = (this.stageWidth - this.txtLevel.width) / 2;
            this.txtScore.y = (this.stageHeight - this.txtScore.height) / 2 - 60;
            this.txtLevel.y = this.txtScore.y - 60;
            moon.GameData.score = data["score"];
        };
        BasicGameOver.prototype.onClick = function (e) {
            //     var btn:MButton=e.currentTarget as MButton;
            //     if(btn==this.btnRestart){
            //         	//console.log("重新开始啦啊啊啊啊");
            //         super.onClick(e);
            //     }else if(btn==this.btnRank){
            //         if(this.rankPanel){
            //             GameData.stage.addChild(this.rankPanel);
            //         }
            //     }
        };
        return BasicGameOver;
    }(BasicGameStart));
    moon.BasicGameOver = BasicGameOver;
    __reflect(BasicGameOver.prototype, "moon.BasicGameOver");
    /**游戏设置面板*/
    var BasicGameSet = (function (_super) {
        __extends(BasicGameSet, _super);
        function BasicGameSet() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        BasicGameSet.prototype.render = function () {
            _super.prototype.render.call(this);
            this.initView();
        };
        BasicGameSet.prototype.initView = function () {
            var containerBg = this.createBackground(0, 0.5);
            this.addChild(containerBg);
            var setbg = new moon.MoonDisplayObject;
            var bgWidth = this.stageWidth >> 1;
            var colorBg = 0XFF9900;
            setbg.type = moon.Const.SHAPE_RECT_ROUND;
            setbg.data = { w: bgWidth * 1.1, h: bgWidth, ew: 100, eh: 100, c: colorBg };
            setbg.setBackground(0XFFFFFF, 5);
            setbg.x = (containerBg.width - bgWidth) >> 1;
            setbg.y = (containerBg.height - bgWidth) >> 1;
            this.addChild(setbg);
            var label1 = new moon.Label("背景音乐", 0XFFFFFF);
            var label2 = new moon.Label("游戏音效", 0XFFFFFF);
            label1.textField.size = 40;
            label2.textField.size = 40;
            label1.x = label2.x = 50;
            label1.y = 50;
            label2.y = 150;
            setbg.addChild(label1);
            setbg.addChild(label2);
            var btn = this.getToggleSwitch();
            btn.x = label1.x + label1.width + 10;
            btn.y = label1.y - 5;
            setbg.addChild(btn);
            this.btnSoundBg = btn;
            var btn = this.getToggleSwitch();
            btn.x = label2.x + label2.width + 10;
            btn.y = label2.y - 5;
            setbg.addChild(btn);
            this.btnSoundEffect = btn;
            var button = new MButton();
            button.label = "关  闭";
            button.x = (setbg.width - button.width) >> 1;
            button.y = 240;
            button.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
            setbg.addChild(button);
            this.btnClose = button;
        };
        BasicGameSet.prototype.getToggleSwitch = function () {
            var normal = moon.Skin.switchOn;
            var down = moon.Skin.switchOn;
            var normal2 = moon.MoonUI.getSwitch(moon.Color.bule, moon.Color.white);
            var down2 = moon.MoonUI.getSwitch(moon.Color.red, moon.Color.white);
            var btn = new moon.MoreSkinButton([normal, down, normal2, down2]);
            btn.toggleSwitch = true;
            btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
            return btn;
        };
        BasicGameSet.prototype.onClick = function (e) {
            var btn = e.currentTarget;
            var value;
            if (btn == this.btnSoundBg) {
                value = this.btnSoundBg.currentPage;
                alertAuto("背景音乐" + (value == 1 ? "开" : "关"), 1);
                BasicGameStorage.localWrite(BasicGameSet.SOUND_BG, value.toString());
                this.dispEvent(moon.MoonEvent.CHANGE, this.btnSoundBg.currentPage, "soundBg");
            }
            else if (btn == this.btnSoundEffect) {
                value = this.btnSoundEffect.currentPage;
                alertAuto("游戏音效" + (value == 1 ? "开" : "关"), 1);
                BasicGameStorage.localWrite(BasicGameSet.SOUND_EFFECT, value.toString());
                this.dispEvent(moon.MoonEvent.CHANGE, this.btnSoundEffect.currentPage, "soundEffect");
            }
            else if (btn == this.btnClose) {
                this.removeFromParent();
                this.dispEvent(moon.MoonEvent.PLAY);
            }
        };
        BasicGameSet.prototype.setValue = function () {
            var value = BasicGameStorage.localRead(BasicGameSet.SOUND_BG) || "1";
            this.btnSoundBg.updatePage(parseInt(value));
            var value = BasicGameStorage.localRead(BasicGameSet.SOUND_EFFECT) || "1";
            this.btnSoundEffect.updatePage(parseInt(value));
        };
        BasicGameSet.SOUND_BG = "sound bg";
        BasicGameSet.SOUND_EFFECT = "sound effect";
        return BasicGameSet;
    }(moon.BasicView));
    moon.BasicGameSet = BasicGameSet;
    __reflect(BasicGameSet.prototype, "moon.BasicGameSet");
    /**游戏积分排行板*/
    var BasicGameRank = (function (_super) {
        __extends(BasicGameRank, _super);
        function BasicGameRank() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.items = [];
            _this.max = 50;
            return _this;
        }
        BasicGameRank.prototype.render = function () {
            _super.prototype.render.call(this);
            this.initView();
        };
        BasicGameRank.prototype.initView = function () {
            this.createBackground(0, 0.5);
            var rankBg = moon.MoonUI.getRect(this.stageWidth - 100, this.stageHeight - 200, 0);
            rankBg.alpha = 0.8;
            this.addChild(rankBg);
            Layout.getIns().setCenterXByPanent(rankBg);
            Layout.getIns().setCenterYByPanent(rankBg);
            var rect = new Rectangle(rankBg.x, rankBg.y, rankBg.width, rankBg.height);
            var dis = 60;
            var line = new Sprite;
            line.graphics.lineStyle(2, 0XFFFFFF);
            line.graphics.moveTo(rect.x, rect.y + dis);
            line.graphics.lineTo(rect.x, rect.y);
            line.graphics.lineTo(rect.right, rect.y);
            line.graphics.lineTo(rect.right, rect.bottom);
            line.graphics.lineTo(rect.x, rect.bottom);
            line.graphics.lineTo(rect.x, rect.y + dis);
            line.graphics.lineTo(rect.right, rect.y + dis);
            this.addChild(line);
            var xnum = 30;
            var btnSkin = moon.MoonUI.getCircle(xnum, 0xffffff);
            var skinX = moon.MoonUI.getX(xnum >> 1, xnum >> 1, 0x00ff00, 4);
            skinX.anchorOffsetX = skinX.anchorOffsetY = xnum >> 2;
            btnSkin.addChild(skinX);
            var btn = new MButton(btnSkin, btnSkin);
            btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
            this.addChild(btn);
            btn.x = rankBg.x + rankBg.width;
            btn.y = rankBg.y;
            var txt = this.createText(0, 0, "分数排行榜");
            Layout.getIns().setCenterXByPanent(txt);
            txt.y = rankBg.y + (dis - txt.height) / 2;
            this.addChild(txt);
            var txt = this.createText(rankBg.x, rankBg.y - dis / 2);
            this.addChild(txt);
            this.txtRank = txt;
            this.txtRank.text = "你的排名:";
            this.conatiner = new Sprite;
            this.addChild(this.conatiner);
            var itemw = rankBg.width - 2;
            for (var i = 0; i < this.max; i++) {
                var item = new RankItem(itemw, i);
                this.conatiner.addChild(item);
                this.items.push(item);
            }
            moon.SimpleLayout.displayRank(this.items, 1);
            var scrollBar = new moon.ScrollBar();
            scrollBar.target = this.conatiner;
            scrollBar.setSize(rect.width, rect.height - dis - 2);
            scrollBar.layout(moon.Const.VERTICAL);
            this.addChild(scrollBar);
            scrollBar.x = rect.x + 1;
            scrollBar.y = rect.y + dis + 2;
        };
        BasicGameRank.prototype.onClick = function (e) {
            this.removeFromParent();
        };
        BasicGameRank.prototype.update = function (data) {
            var len = this.max;
            var myRank = -1;
            for (var i = 0; i < len; i++) {
                if (i <= this.max) {
                    var score = 100;
                    var item = this.items[i];
                    item.txtScore.text = "" + score;
                    if (i < len - 1) {
                        var next = 90;
                        if (moon.GameData.score > next && moon.GameData.score <= score) {
                            myRank = i;
                        }
                    }
                }
            }
            if (myRank > 0)
                this.txtRank.text = "你的排名:" + myRank;
            else
                this.txtRank.text = "未上榜";
        };
        return BasicGameRank;
    }(moon.BasicView));
    moon.BasicGameRank = BasicGameRank;
    __reflect(BasicGameRank.prototype, "moon.BasicGameRank");
    var RankItem = (function (_super) {
        __extends(RankItem, _super);
        function RankItem(w, rank) {
            var _this = _super.call(this) || this;
            _this.colors = [0, 0XDD823B, 0XD2A85E, 0XDFD164];
            _this.w = w;
            _this.rank = rank + 1;
            _this.initView();
            return _this;
        }
        RankItem.prototype.initView = function () {
            var bg = this.createRect(this.w, 80, 0);
            bg.alpha = this.rank % 2 == 0 ? 0.6 : 0.1;
            this.addChild(bg);
            this.txtRank = this.createText(150, 0);
            this.txtScore = this.createText(350, 0);
            if (this.rank <= 3) {
                this.txtRank.textColor = this.txtScore.textColor = this.colors[this.rank];
            }
            this.txtRank.text = String(this.rank);
            //this.txtScore.text=String(10000-this.rank);
            this.txtScore.text = String(0);
            Layout.getIns().setCenterYByPanent(this.txtRank);
            Layout.getIns().setCenterYByPanent(this.txtScore);
        };
        return RankItem;
    }(moon.BasicView));
    moon.RankItem = RankItem;
    __reflect(RankItem.prototype, "moon.RankItem");
    var SetButton = (function (_super) {
        __extends(SetButton, _super);
        function SetButton() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        SetButton.prototype.render = function () {
            _super.prototype.render.call(this);
            var skin1 = this.getSkin();
            var skin2 = this.getSkin(0XFF5500);
            //skin.filters=[new egret.GlowFilter(0)];
            this.statusNormal = skin1;
            this.statusDown = skin2;
            this.updateSkin(this.statusNormal);
        };
        SetButton.prototype.getSkin = function (bgc) {
            if (bgc === void 0) { bgc = 0XFF9900; }
            var colorBg = bgc;
            var colorIcon = 0X6A4000;
            var container = new Sprite;
            var bgWidth = 90;
            var bg = new moon.MoonDisplayObject;
            bg.type = moon.Const.SHAPE_RECT_ROUND;
            bg.data = { w: bgWidth, h: bgWidth, ew: 30, eh: 30, c: colorBg };
            bg.anchorOffsetX = bg.anchorOffsetY = bgWidth >> 1;
            container.addChild(bg);
            container.addChild(moon.MoonUI.getCircle(30, colorIcon));
            var len = 8;
            var rotation = 360 / len;
            for (var i = 0; i < len; i++) {
                var line = moon.MoonUI.getRect(15, 80, colorIcon);
                line.anchorOffsetX = line.width >> 1;
                line.anchorOffsetY = line.height >> 1;
                line.rotation = rotation * i;
                container.addChild(line);
            }
            container.addChild(moon.MoonUI.getCircle(20, colorBg));
            container.addChild(moon.MoonUI.getCircle(6, colorIcon));
            container.anchorOffsetX = container.anchorOffsetY = -(bgWidth / 2 + 4);
            return container;
        };
        return SetButton;
    }(MButton));
    moon.SetButton = SetButton;
    __reflect(SetButton.prototype, "moon.SetButton");
    /**游戏数据存储*/
    var BasicGameStorage = (function () {
        function BasicGameStorage() {
        }
        /**只能内部访问,在外部修改gameId */
        BasicGameStorage.getGameIdKey = function (key) { return moon.GameData.gameId + key; };
        /**本地 数据写入*/
        BasicGameStorage.localWrite = function (key, value) {
            egret.localStorage.setItem(this.getGameIdKey(key), value);
        };
        /**本地 数据读取*/
        BasicGameStorage.localRead = function (key) {
            return egret.localStorage.getItem(this.getGameIdKey(key));
        };
        /**本地 数据删除*/
        BasicGameStorage.localRemove = function (key) {
            egret.localStorage.removeItem(this.getGameIdKey(key));
        };
        /**本地 数据清空*/
        BasicGameStorage.localClear = function () {
            egret.localStorage.clear();
        };
        /**服务器 数据写入*/
        BasicGameStorage.serverWrite = function () { };
        /**服务器 数据读取*/
        BasicGameStorage.serverRead = function () { return ""; };
        /**服务器 数据删除*/
        BasicGameStorage.serverRemove = function () { };
        return BasicGameStorage;
    }());
    moon.BasicGameStorage = BasicGameStorage;
    __reflect(BasicGameStorage.prototype, "moon.BasicGameStorage");
    /**初始化游戏*/
    var GameMoon = (function () {
        function GameMoon() {
        }
        GameMoon.init = function (stage) {
            //移动端与PC端使用不同模式
            egret.Capabilities.isMobile ? stage.scaleMode = egret.StageScaleMode.FIXED_WIDTH : stage.scaleMode = egret.StageScaleMode.SHOW_ALL;
            //保存好舞台数据 请使用 render()方法中的 this.stageWidth;
            //GameData.stageWidth=stage.stageWidth;
            //GameData.stageHeight=stage.stageHeight;
            moon.GameData.stage = stage;
            //初始化部分功能
            moon.TipsManager.getIns().init(stage);
            moon.LogManager.getIns().init(stage);
            moon.AlertManager.getIns().init(stage);
        };
        return GameMoon;
    }());
    moon.GameMoon = GameMoon;
    __reflect(GameMoon.prototype, "moon.GameMoon");
    /**游戏间的工具类*/
    var GameUtils = (function () {
        function GameUtils() {
        }
        /**把数字转换成时间格式,showNum为3时00:00:00,为2时00:00,为1时00*/
        GameUtils.getTimeFormatByNum = function (num, type, showNum) {
            if (type === void 0) { type = ":"; }
            if (showNum === void 0) { showNum = 3; }
            var s;
            var hour;
            var minute;
            var second;
            if (showNum == 1) {
                second = this.numberFormat(num);
                return second;
            }
            else if (showNum == 2) {
                minute = this.numberFormat((num / 60));
                second = this.numberFormat(num % 60);
                return minute + type + second;
            }
            else {
                hour = this.numberFormat(num / 60 / 60 >> 0);
                minute = this.numberFormat((num / 60) % 60);
                second = this.numberFormat(num % 60);
                return hour + type + minute + type + second;
            }
        };
        /**数字格式，把小于10的数在前面加个0*/
        GameUtils.numberFormat = function (num) {
            num = Math.floor(num);
            if (num >= 10)
                return "" + num;
            else
                return "0" + num;
        };
        /***两点间的距离 */
        GameUtils.twoDistance = function (a, b) {
            var x = a.x - b.x;
            var y = a.y - b.y;
            return Math.sqrt(x * x + y * y);
        };
        return GameUtils;
    }());
    moon.GameUtils = GameUtils;
    __reflect(GameUtils.prototype, "moon.GameUtils");
})(moon || (moon = {}));
var control;
(function (control) {
    var ControlBasic = (function () {
        function ControlBasic(stage) {
            this.stage = stage;
        }
        /** 打开事件*/
        ControlBasic.prototype.open = function () {
            this.close();
            this.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouch, this);
        };
        /** 关闭事件*/
        ControlBasic.prototype.close = function () {
            this.stage.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouch, this);
        };
        ControlBasic.prototype.onTouch = function (e) {
            switch (e.type) {
                case egret.TouchEvent.TOUCH_BEGIN:
                    this.posStart = new egret.Point(e.stageX, e.stageY);
                    this.controlStart();
                    break;
                case egret.TouchEvent.TOUCH_MOVE:
                    this.posMove = new egret.Point(e.stageX, e.stageY);
                    this.controlMove();
                    break;
                case egret.TouchEvent.TOUCH_END:
                    this.posEnd = new egret.Point(e.stageX, e.stageY);
                    this.controlEnd();
                    break;
            }
        };
        /** 手指按下*/
        ControlBasic.prototype.controlStart = function () {
            if (this.startBackFun != null) {
                this.startBackFun(this.posStart);
            }
            this.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouch, this);
            this.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
        };
        /** 手指移动*/
        ControlBasic.prototype.controlMove = function () {
            if (this.moveBackFun != null) {
                this.moveBackFun(this.posMove);
            }
        };
        /** 手指离开*/
        ControlBasic.prototype.controlEnd = function () {
            if (this.endBackFun != null) {
                this.endBackFun(this.posEnd);
            }
            this.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouch, this);
            this.stage.removeEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
        };
        return ControlBasic;
    }());
    control.ControlBasic = ControlBasic;
    __reflect(ControlBasic.prototype, "control.ControlBasic");
    /**
     * @author vinson
     * 创建时间：2017-12-28 上午9:36:42
     * 控制杆自由控制移动
     */
    //     export class ControlBarMove extends ControlBasic{
    //         private controlBg:egret.DisplayObject;
    //         private controlBar:egret.DisplayObject;
    //         private isDrag:boolean;
    //         constructor(stage:egret.Stage,controlBar:egret.DisplayObject,controlBg:egret.DisplayObject) {
    //             super(stage);
    //             this.controlBar=controlBar;
    //             this.controlBg=controlBg;
    //         }
    //         /** 手指按下*/
    //         protected controlStart(): void {
    //            if(this.controlBar.hitTestPoint(this.posStart.x,this.posStart.y)){
    //                 super.controlStart();
    //                 this.isDrag=true;
    //             }
    //         }
    //         protected controlMove(): void {
    //             if(this.isDrag==false) return;
    //             var x:number=this.posMove.x,y:number=this.posMove.y;
    //             var bg=this.controlBg;
    //             var bar=this.controlBar;
    //             var cx=bg.x;
    //             var cy=bg.y;
    //             var dx=x-cx;
    //             var dy=y-cy;
    //             var ds=Math.sqrt(dx*dx+dy*dy);
    //             var r=bg.width>>1;
    //             var conA=dx/ds;
    //             var sinA=dy/ds;
    //             if(ds<r){//在边内时的处理
    //                 bar.x=x;
    //                 bar.y=y;
    //             }else{//超出边界时的处理
    //                 bar.x=cx+conA*r;
    //                 bar.y=cy+sinA*r;
    //             }
    //             if(this.moveBackFun!=null){
    //                 var value:egret.Point=new egret.Point(bar.x-bg.x,bar.y-bg.y);
    //                 this.moveBackFun(value);
    //             }
    //         }
    //         protected controlEnd(): void {
    //             this.isDrag=false;
    //             this.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouch, this);
    //             this.stage.removeEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
    //             var bg=this.controlBg;
    //             var bar=this.controlBar;
    //             bar.x=bg.x;
    //             bar.y=bg.y;
    //             if(this.endBackFun!=null){
    //                 this.endBackFun(this.posEnd);
    //              }
    //         }
    //     }
    //     /**
    // 	 * @author vinson
    // 	 * 创建时间：2017-12-28 上午9:36:42
    // 	 * 手指滑动，向上向下向左向右滑动
    // 	 */
    //     export class ControlFingerMove extends ControlBasic{
    //         public moveEndBackFun:any;
    //         constructor(stage:egret.Stage) {
    //             super(stage);
    //         }
    //         protected controlEnd(): void {
    //             this.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouch, this);
    //             this.stage.removeEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
    //             var disx:number=this.posEnd.x-this.posStart.x;
    //             var disy:number=this.posEnd.y-this.posStart.y;
    //             var value:egret.Point=new egret.Point(0,0);
    //             if(Math.abs(disx)>Math.abs(disy)){//左右
    //                value.x=disx>0?1:-1;
    //             }else{//上下
    //                value.y=disy>0?1:-1;
    //             }
    //             if(this.endBackFun!=null){
    //                 this.endBackFun(this.posEnd);
    //             }
    //             if(this.moveEndBackFun!=null){
    //                 this.moveEndBackFun(value);
    //             }
    //         }
    //     }
    //     /**
    // 	 * @author vinson
    // 	 * 创建时间：2017-12-28 上午9:36:42
    // 	 * 可示对象自由拖动
    // 	 */
    //     export class ControlDrag extends ControlBasic{
    //         display:egret.DisplayObject;
    //         distance:egret.Point;
    //         isDrag:boolean;
    //         constructor(stage:egret.Stage,display:egret.DisplayObject) {
    //             super(stage);
    //             this.display=display;
    //             this.distance=new egret.Point;
    //         }
    //         public set target(value:egret.DisplayObject){
    //             this.display=value;
    //         }
    //         protected controlStart(): void {
    //             if(this.display.hitTestPoint(this.posStart.x,this.posStart.y)){
    //                 super.controlStart();
    //                 this.isDrag=true;
    //                 this.distance.x = this.posStart.x - this.display.x;
    //                 this.distance.y = this.posStart.y - this.display.y;
    //             }
    //         }
    //         protected controlMove(): void {
    //             if(this.isDrag){
    //                 super.controlMove();
    //                 this.display.x = this.posMove.x - this.distance.x;
    //                 this.display.y = this.posMove.y - this.distance.y;
    //             }
    //         }
    //         protected controlEnd(): void {
    //             this.isDrag=false;
    //             super.controlEnd();
    //             if(this.endBackFun!=null){
    //                 this.endBackFun();
    //              }
    //         }
    //     }
    //     /**
    // 	 * @author vinson
    // 	 * 创建时间：2017-12-28 上午9:36:42
    // 	 * 多点按下与松开的触控管理
    // 	 */
    //     export class ControlMoreTab extends ControlBasic{
    //         private id:number;
    //         private nodes:any[]=[];
    //         /**datas:[{display:display:backCall:backCall}]*/
    //         constructor(stage:egret.Stage,datas:any[]) {
    //             super(stage);
    //             for(var i:number=0;i<datas.length;i++){
    //                 var obj=datas[i];
    //                 var node:MorePointNode=new MorePointNode(obj.display,obj.backCall);
    //                 this.nodes.push(node);
    //             }
    //         }
    //         protected onTouch(e: egret.TouchEvent){
    //             this.id=e.touchPointID;
    //             super.onTouch(e);
    //         }
    //         private check(x:number,y:number,type:number):void
    //         {
    //             var nodes:any[]=this.nodes;
    //             for(var i:number=0;i<nodes.length;i++){
    //                 var node:MorePointNode=nodes[i];
    //                 if(type==1){//按下
    //                     if(node.display.hitTestPoint(x,y)){
    //                         node.id=this.id;
    //                         node.backCall(type);
    //                     }
    //                 }else{//松开
    //                     if(node.id==this.id){
    //                         node.id=-1;
    //                         node.backCall(type);
    //                     }
    //                 }
    //             }
    //         }
    //         protected controlStart(): void {
    //             this.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouch, this);
    //             this.check(this.posStart.x,this.posStart.y,1);
    //         }
    //         protected controlEnd():void{
    //             super.controlEnd();
    //            this.check(this.posEnd.x,this.posEnd.y,0);
    //         }
    //     }
    //     export class MorePointNode
    //     {
    //         public id:number;
    //         public display:egret.DisplayObject;
    //         public backCall:Function;
    //         constructor(display:egret.DisplayObject,backCall:Function) {
    //             this.display=display;
    //             this.backCall=backCall;
    //         }
    //     }
})(control || (control = {}));
var egretToWX = (function (_super) {
    __extends(egretToWX, _super);
    /**单例 */
    function egretToWX() {
        var _this = _super.call(this) || this;
        //	private closeBtn: eui.Image = new eui.Image();
        _this.isdisplay = false;
        return _this;
    }
    egretToWX.getInstance = function () {
        if (this.instance == null) {
            this.instance = new egretToWX();
        }
        return this.instance;
    };
    /**1 设置舞台*/
    egretToWX.prototype.setGameHandle = function (game) {
        this.gameHandle = game;
    };
    /**2 排行榜按钮绑定事件*/
    egretToWX.prototype.paihangBtnClick = function () {
        var openDataContext = wx.getOpenDataContext();
        if (this.isdisplay) {
            this.bitmap.parent && this.bitmap.parent.removeChild(this.bitmap);
            this.rankingListMask.parent && this.rankingListMask.parent.removeChild(this.rankingListMask);
            this.buttonr.parent && this.buttonr.parent.removeChild(this.buttonr);
            this.isdisplay = false;
        }
        else {
            //处理遮罩，避免开放数据域事件影响主域。
            this.rankingListMask = new egret.Shape();
            this.rankingListMask.graphics.beginFill(0x000000, 1);
            this.rankingListMask.graphics.drawRect(0, 0, this.gameHandle.stage.width, this.gameHandle.stage.height);
            this.rankingListMask.graphics.endFill();
            this.rankingListMask.alpha = 0.5;
            this.rankingListMask.touchEnabled = true;
            this.gameHandle.addChild(this.rankingListMask);
            console.log("调取开放域");
            //创建排行榜按钮
            this.buttonr = new MButton(new MImage("fanhui_png"), new MImage("fanhui_png"));
            this.buttonr.addEventListener(egret.TouchEvent.TOUCH_TAP, this.button, this);
            this.buttonr.x = 80;
            this.buttonr.y = 0;
            this.gameHandle.addChild(this.buttonr);
            //简单实现，打开这关闭使用一个按钮。
            // this.gameHandle.addChild(this.gameHandle.btnClose);
            //主要示例代码开始
            var bitmapdata_1 = new egret.BitmapData(window["sharedCanvas"]);
            bitmapdata_1.$deleteSource = false;
            var texture = new egret.Texture();
            texture._setBitmapData(bitmapdata_1);
            this.bitmap = new egret.Bitmap(texture);
            this.bitmap.width = this.gameHandle.stage.stageWidth;
            this.bitmap.height = this.gameHandle.stage.stageHeight;
            this.gameHandle.addChild(this.bitmap);
            // this.closeBtn.texture = RES.getRes("guanbi");
            // this.gameHandle.addChild(this.closeBtn);
            // this.closeBtn.x = 830;
            // this.closeBtn.y = 130;
            // this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.paihangBtnClick, this);
            egret.startTick(function (timeStarmp) {
                egret.WebGLUtils.deleteWebGLTexture(bitmapdata_1.webGLTexture);
                bitmapdata_1.webGLTexture = null;
                return false;
            }, this);
            //主要示例代码结束    
            this.isdisplay = true;
        }
        //发送消息
        openDataContext.postMessage({
            isDisplay: this.isdisplay,
            text: 'hello',
            year: (new Date()).getFullYear()
        });
    };
    egretToWX.prototype.button = function () {
        egretToWX.getInstance().setGameHandle(this);
        //调去egretToWX脚本
        egretToWX.getInstance().paihangBtnClick();
    };
    /**
     * 3 托管玩家的数据 完成一次游戏之后提交数据 只有提交过数据的玩家才被承认是玩过这个游戏的玩家
     * KVData参数 例：data={[key:"score",value:"1234""],[key:"length",value:"1234"],[key:"kill",value:"1234""]}
     */
    egretToWX.prototype.storageUserData = function (KVData) {
        var object = {
            KVDataList: KVData,
            success: function (res) { console.log("托管数据成功 " + res); },
            fail: function (res) { console.log("托管数据失败 " + res.Msg); },
            complete: function (res) { console.log("完成数据托管操作"); }
        };
        wx.setUserCloudStorage(object);
    };
    /**
     * 4、根据keyList删除玩家托管的对应数据
     * keyListData参数 keyListData={["score","length","kill"]}
     */
    egretToWX.prototype.removeUserStorageData = function (keyListData) {
        var object = {
            keyList: keyListData,
            success: function (res) { console.log("删除托管数据成功 " + res); },
            fail: function (res) { console.log("删除托管数据失败 " + res.data); },
            complete: function (res) { console.log("完成删除数据操作"); }
        };
        wx.removeUserCloudStorage(object);
    };
    return egretToWX;
}(eui.Component));
__reflect(egretToWX.prototype, "egretToWX");
/**
 * 开始界面
 * 实现开始界面逻辑
 */
var Gamebegin = (function (_super) {
    __extends(Gamebegin, _super);
    function Gamebegin() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Gamebegin.prototype.render = function () {
        _super.prototype.render.call(this);
        /**开始界面背景图 */
        this.createImageBg("beijing_png");
        // /**背景音乐预先加载好 */
        // SoundControl.getIns().play(MUSIC_BG, 0, 9999);//背景音乐
        //   this.btnRestartadd = this.createMButton("kaishi_png", 340, 800);
        /**昵称 */
        this.txtMyScore = this.createText(10, 120);
        this.updateScore();
        /**获取微信数据 */
        this.GetMessage();
        /**资源加载 */
        this.upload();
        // window.href = "http://www.baidu.com";
        // window.open("http://www.baidu.com");
    };
    Gamebegin.prototype.initView = function () {
        //需要复写
    };
    /**获取 */
    Gamebegin.prototype.initGame = function () {
        this.updateScore(); //昵称
    };
    /**资源加载 */
    Gamebegin.prototype.upload = function () {
        /**开始按钮 */
        this.btn = new MButton(new MImage("kaishi_png"), new MImage("kaishi_png"));
        this.btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
        this.btn.x = 340;
        this.btn.y = 800;
        this.addChild(this.btn);
        egret.Tween.get(this.btn).to({ scaleX: 0.8, scaleY: 0.8 }, 100).to({ scaleX: 1, scaleY: 1 }, 100);
        /**音乐关闭 */
        this.music = new MButton(new MImage("shengyin_png"), new MImage("shengyin_png"));
        this.music.x = 560;
        this.music.y = 10;
        this.music.addEventListener(egret.TouchEvent.TOUCH_TAP, this.muisc_add, this);
        this.addChild(this.music);
        /**音乐开关 */
        this.music_remove = new MButton(new MImage("shengyi_guanbi_png"), new MImage("shengyi_guanbi_png"));
        this.music_remove.x = 560;
        this.music_remove.y = 10;
        this.music_remove.addEventListener(egret.TouchEvent.TOUCH_TAP, this.muisc_remove, this);
        // this.addChild(this.music_remove);
        /**游戏玩法 按钮 */
        this.playing = new MButton(new MImage("wanfa_png"), new MImage("wanfa_png"));
        this.playing.x = 560;
        this.playing.y = 90;
        this.playing.addEventListener(egret.TouchEvent.TOUCH_TAP, this.addplaying, this);
        this.addChild(this.playing);
    };
    /**玩法 */
    Gamebegin.prototype.addplaying = function () {
        /**打开玩法界面  所有按钮不接受触摸事件 */
        this.btn.touchEnabled = false; //开始按钮
        this.music.touchEnabled = false; //音乐关闭
        this.music_remove.touchEnabled = false; //音乐开关
        this.playing.touchEnabled = false; //游戏玩法
        this.playingimage = new MImage("wenzi_jieshao_png");
        this.playingimage.x = 90;
        this.playingimage.y = 400;
        this.addChild(this.playingimage);
        this.close = new MButton(new MImage("jieshao_ganbi_png"), new MImage("jieshao_ganbi_png"));
        this.close.x = 460;
        this.close.y = 420;
        this.close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.addclose, this);
        this.addChild(this.close);
    };
    /**关闭玩法界面 */
    Gamebegin.prototype.addclose = function () {
        /**关闭玩法界面 所有按钮接受触摸事件 */
        this.btn.touchEnabled = true; //开始按钮
        this.music.touchEnabled = true; //音乐关闭
        this.music_remove.touchEnabled = true; //音乐开关
        this.playing.touchEnabled = true; //游戏玩法
        this.removeChild(this.playingimage);
        this.removeChild(this.close);
    };
    /**音乐的关闭 */
    Gamebegin.prototype.muisc_add = function () {
        SoundControl.getIns().stop(MUSIC_BG);
        SoundControl.getIns().stop(MUSIC_FIRE);
        // SoundControl.getIns().isNoVolume = 0;
        // SoundControl.getIns().setIsNoVolume(0);//音效静音
        this.removeChild(this.music);
        this.addChild(this.music_remove);
    };
    /**音乐的开关 */
    Gamebegin.prototype.muisc_remove = function () {
        SoundControl.getIns().play(MUSIC_BG); //音效
        // SoundControl.getIns().play(MUSIC_FIRE);//特效音效
        // SoundControl.getIns().isNoVolume = 1;
        // SoundControl.getIns().setIsNoVolume(1);//播放音效
        //SoundControl.getIns().play(MUSIC_BG, 0, 9999);//背景音乐
        this.removeChild(this.music_remove);
        this.addChild(this.music);
    };
    /**获取微信数据 */
    Gamebegin.prototype.GetMessage = function () {
        return __awaiter(this, void 0, void 0, function () {
            var userinfo;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, platform.login()];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, platform.showShareMenu()];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, platform.getUserInfo()];
                    case 3:
                        userinfo = _a.sent();
                        console.log(userinfo);
                        //	this.l.text = userinfo.nickName;
                        this.nickName = userinfo.nickName; //将文本信息改为玩家昵称
                        this.updateScore();
                        if (userinfo.avatarUrl != null) {
                            RES.getResByUrl(userinfo.avatarUrl, this.getResComplete, this, "image"); //将玩家头像信息添加到预加载中
                        }
                        else {
                            return [2 /*return*/];
                        }
                        return [2 /*return*/];
                }
            });
        });
    };
    Gamebegin.prototype.getResComplete = function (date) {
        var head = new egret.Bitmap(date);
        head.x = 10;
        head.y = 10;
        head.width = 100;
        head.height = 100;
        this.addChild(head);
    };
    /**昵称 */
    Gamebegin.prototype.updateScore = function () {
        this.myScore = this.nickName;
        this.txtMyScore.text = "昵称:" + this.myScore;
    };
    return Gamebegin;
}(moon.BasicGameStart));
__reflect(Gamebegin.prototype, "Gamebegin");
var MUSIC_CLICK_BTN = "click_mp3";
var MUSIC_HIT = "hit_mp3";
var MUSIC_ADDNUM = "addNum_mp3";
var MUSIC_FIRE = "fire_mp3";
var MUSIC_FLOOR = "floor_mp3";
var MUSIC_BG = "background_mp3";
var EVENT_FIRE = "event fire";
var EVENT_REMOVE = "event remove";
var TYPE_HAND = "type hand";
var ICON_ADD = "addIcon_png";
var SHAPE = { rect: "rect", circle: "circle" }; //形状
var OVER_DIS = 200;
var GameControl = (function (_super) {
    __extends(GameControl, _super);
    function GameControl() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.names = []; //数字刚体皮肤名字
        _this.removeSkins = []; //需要删除刚体的皮肤
        _this.minBodyCount = 1; //数字刚体的最少数值
        _this.zuqiu = [];
        _this.my_ball = [];
        _this.isHoled = false; //是否进洞
        _this.isStopPanel = false; //是否掉结束界面
        _this.shape = new egret.Shape();
        return _this;
    }
    GameControl.prototype.render = function () {
        _super.prototype.render.call(this);
        // trace("v1.1");
        GameData.stageHeight = this.stageHeight;
        GameData.stageWidth = this.stageWidth;
        SoundControl.getIns().addItem(MUSIC_HIT);
        SoundControl.getIns().addItem(MUSIC_ADDNUM);
        SoundControl.getIns().addItem(MUSIC_FIRE);
        SoundControl.getIns().addItem(MUSIC_FLOOR);
        SoundControl.getIns().addItem(MUSIC_BG, true);
        SoundControl.getIns().play(MUSIC_BG, 0, 9999);
        this.createImageBg("ditu_png");
        var world = new P2World(0, 200);
        this.addChild(world);
        this.world = world;
        world.loopBackFun = this.loopP2World.bind(this);
        /**分数 */
        this.txtMyScore = this.createText(450, 50);
        this.updateScore();
        /**显示 */
        this.txtLevel = this.createText(250, 550);
        /**计时器 */
        this.txtTime = this.createText(250, 0);
        // this.updateTime();
        // GameControl.Maxtime = 100;
        // this.time = moon.BasicGameStart.mavti;
        this.time = 120;
        this.material = new p2.Material();
        //创建左右刚体
        var leftTop = this.createBody2("zuoshang1_png");
        leftTop.position = [63, 308];
        var leftTop1 = new MImage("zuoshang_png");
        leftTop1.anchorOffsetX = leftTop1.width / 2;
        leftTop1.anchorOffsetY = leftTop1.height / 2;
        leftTop1.x = 63;
        leftTop1.y = 308;
        this.addChild(leftTop1);
        var leftDown = this.createBody2("zuoshang1_png");
        leftDown.position = [63, 825];
        var leftTop1 = new MImage("zuoshang_png");
        leftTop1.anchorOffsetX = leftTop1.width / 2;
        leftTop1.anchorOffsetY = leftTop1.height / 2;
        leftTop1.x = 63;
        leftTop1.y = 825;
        this.addChild(leftTop1);
        var rightTop = this.createBody2("youshang1_png");
        rightTop.position = [this.getRight(67), 306];
        var rightTop1 = new MImage("youshang_png");
        rightTop1.anchorOffsetX = rightTop1.width / 2;
        rightTop1.anchorOffsetY = rightTop1.height / 2;
        rightTop1.x = this.getRight(67);
        rightTop1.y = 306;
        this.addChild(rightTop1);
        var rightDown = this.createBody2("youshang1_png");
        rightDown.position = [this.getRight(67), 825];
        var rightTop1 = new MImage("youshang_png");
        rightTop1.anchorOffsetX = rightTop1.width / 2;
        rightTop1.anchorOffsetY = rightTop1.height / 2;
        rightTop1.x = this.getRight(67);
        rightTop1.y = 825;
        this.addChild(rightTop1);
        //创建顶部底部刚体
        var top = this.createBody2("shang1_png");
        top.position = [322, 52];
        var top1 = new MImage("shang_png");
        top1.anchorOffsetX = top1.width / 2;
        top1.anchorOffsetY = top1.height / 2;
        top1.x = 322;
        top1.y = 52;
        this.addChild(top1);
        var down = this.createBody2("xia1_png");
        down.position = [315, 1084.5];
        var down1 = new MImage("xia_png");
        down1.anchorOffsetX = down1.width / 2;
        down1.anchorOffsetY = down1.height / 2;
        down1.x = 315;
        down1.y = 1084.5;
        this.addChild(down1);
        //动画
        // this.Init();
        // this.createArmation("qiu_2");
        //创建球洞
        var cun_dong = [];
        var cun_dong2 = [];
        for (var i = 0; i < 3; i++) {
            var dong = this.createBody2("heidong02_png");
            var dong2 = new MImage("heidong01_png");
            this.addChild(dong2);
            dong2.anchorOffsetX = dong2.width / 2;
            dong2.anchorOffsetY = dong2.height / 2;
            dong.userData["dong"] = true;
            dong.position = [50, 65 + 510 * i];
            // dong2.x = 53.5;
            // dong2.y = 50 + 510 * i;
            cun_dong.push(dong2);
        }
        cun_dong[0].x = 53.5;
        cun_dong[0].y = 50;
        cun_dong[1].x = 40;
        cun_dong[1].y = 565;
        cun_dong[2].x = 53.5;
        cun_dong[2].y = 1083;
        for (var i = 0; i < 3; i++) {
            var dong = this.createBody2("heidong02_png");
            var dong2 = new MImage("heidong01_png");
            this.addChild(dong2);
            dong2.anchorOffsetX = dong2.width / 2;
            dong2.anchorOffsetY = dong2.height / 2;
            dong.userData["dong"] = true;
            dong.position = [590, 62 + 510 * i];
            cun_dong2.push(dong2);
        }
        cun_dong2[0].x = 585;
        cun_dong2[0].y = 50;
        cun_dong2[1].x = 595;
        cun_dong2[1].y = 565;
        cun_dong2[2].x = 585;
        cun_dong2[2].y = 1083;
        //摆球
        this.baiBall();
        //给所有球加标签
        this.zuqiu[0].userData["taiqiu0"] = true; //标签
        this.zuqiu[1].userData["taiqiu1"] = true;
        this.zuqiu[2].userData["taiqiu2"] = true;
        this.zuqiu[3].userData["taiqiu3"] = true;
        this.zuqiu[4].userData["taiqiu4"] = true;
        this.zuqiu[5].userData["taiqiu5"] = true;
        this.zuqiu[6].userData["taiqiu6"] = true;
        this.zuqiu[7].userData["taiqiu7"] = true;
        this.zuqiu[8].userData["taiqiu8"] = true;
        this.zuqiu[9].userData["taiqiu9"] = true;
        this.zuqiu[10].userData["taiqiu10"] = true;
        this.zuqiu[11].userData["taiqiu11"] = true;
        this.zuqiu[12].userData["taiqiu12"] = true;
        this.zuqiu[13].userData["taiqiu13"] = true;
        this.zuqiu[14].userData["taiqiu14"] = true;
        //更改所有球皮肤
        this.zuqiu[0].userData.skin = this.createSkin("chen1_png"); //皮肤
        this.zuqiu[1].userData.skin = this.createSkin("hei_png");
        this.zuqiu[2].userData.skin = this.createSkin("hong_png");
        this.zuqiu[3].userData.skin = this.createSkin("hong1_png");
        this.zuqiu[4].userData.skin = this.createSkin("huang1_png");
        this.zuqiu[5].userData.skin = this.createSkin("huang02_png");
        this.zuqiu[6].userData.skin = this.createSkin("juhong_png");
        this.zuqiu[7].userData.skin = this.createSkin("lan_png");
        this.zuqiu[8].userData.skin = this.createSkin("lanlu_png");
        this.zuqiu[9].userData.skin = this.createSkin("lu_png");
        this.zuqiu[10].userData.skin = this.createSkin("shenlanse_png");
        this.zuqiu[11].userData.skin = this.createSkin("yingguanglu1_png");
        this.zuqiu[12].userData.skin = this.createSkin("zi_png");
        this.zuqiu[13].userData.skin = this.createSkin("zihong_png");
        this.zuqiu[14].userData.skin = this.createSkin("chen1_png");
        //母球
        this.createMother();
        // //创建炮
        // var gun: Gun = new Gun;
        // gun.addEvent(EVENT_FIRE, this.onFire, this)
        // this.addChild(gun);
        // this.gun = gun;
        // gun.x = GameControl.motherBall.position[0];
        // gun.y = GameControl.motherBall.position[1];
        // console.log(Gun.distance + " ++++++");
        this.container = new Sprite;
        this.addChild(this.container);
        var conMask = moon.MoonUI.getRect(GameData.stageWidth, GameData.stageHeight - 200, 0, 0, 160);
        this.container.mask = conMask;
        var controlGun = new control.ControlBasic(this.stage);
        //controlGun.open();
        controlGun.startBackFun = this.startBackFun.bind(this);
        controlGun.moveBackFun = this.controlMove.bind(this);
        controlGun.endBackFun = this.endBackFun.bind(this);
        this.controlGun = controlGun;
        world.p2World.on("beginContact", this.onHitBegin.bind(this));
    };
    //动画
    GameControl.prototype.Init = function () {
        var ske = RES.getRes("qiu_2_ske_json");
        var tex = RES.getRes("qiu_2_tex_json");
        var texture = RES.getRes("qiu_2_tex_png");
        var factory = new dragonBones.EgretFactory();
        factory.addDragonBonesData(factory.parseDragonBonesData(ske));
        factory.addTextureAtlasData(factory.parseTextureAtlasData(tex, texture));
        this.armature = factory.buildArmature("qiu_2");
        var armatureDisplay = this.armature.display;
        armatureDisplay.x = 300;
        armatureDisplay.y = 600;
        this.armature.clock = factory.clock;
    };
    //生成动作
    GameControl.prototype.createArmation = function (armationName, playTimes) {
        this.armature.animation.play(armationName, playTimes);
        this.armature.animation.timeScale = 1;
    };
    GameControl.prototype.stopArmation = function () {
        this.armature.animation.reset();
    };
    //创建母球
    GameControl.prototype.createMother = function () {
        GameControl.motherBall = this.createBody("bai_png");
        GameControl.motherBall.userData["motherhit"] = true;
        GameControl.motherBall.position = [320, 850];
    };
    //摆球
    GameControl.prototype.baiBall = function () {
        var r = 40; //台球的直径
        var b = 1;
        var maxR = 5 * r; //最大的一排的总直径
        for (var i = 5; i > 0; i--) {
            b++;
            for (var j = 0; j < i; j++) {
                var sp = this.createBody("shenlanse_png");
                //      console.log("小球的质量是" + sp.mass);
                sp.position = [250 + (maxR - (i * r)) / 2 + j * r, 100 + b * r];
                sp.damping = 0.6;
                this.zuqiu.push(sp);
                this.my_ball.push(sp);
            }
        }
    };
    GameControl.prototype.initView = function () {
        //需要复写
    };
    GameControl.prototype.initGame = function () {
        this.updateTime();
        this.myScore = 0;
        var str2 = "";
        this.level = str2;
        this.updateScore(); //分数
        this.controlGun.open();
        this.ganShow();
        // //创建炮
        // var gun: Gun = new Gun;
        // gun.addEvent(EVENT_FIRE, this.onFire, this)
        // this.addChild(gun);
        // this.gun = gun;
        // gun.x = GameControl.motherBall.position[0];
        // gun.y = GameControl.motherBall.position[1];
    };
    /**复活 */
    GameControl.prototype.revive = function () {
        //  this.moveNum = 0;
        //   this.ballNum = 0;
        //  this.play();
        //  this.controlGun.open();
    };
    GameControl.prototype.setBottom = function (height, distance) {
        return GameData.stageHeight - height - distance;
    };
    GameControl.prototype.moveNumBody = function () {
        // var bodys = this.world.p2World.bodies;
        // var l: number = bodys.length;
        // for (var i: number = 0; i < l; i++) {
        //     var body: p2.Body = bodys[i];
        //     if (body.userData && body.userData.skin) {
        //         if (body.userData["num"]) {
        //             body.position[1] -= 10;
        //             if (body.position[1] <= OVER_DIS) {
        //                 if (body.userData.skin.imageName != ICON_ADD) {
        //                     this.over();
        //                     return;
        //                 }
        //             }
        //         }
        //     }
        // }
    };
    GameControl.prototype.over = function () {
        _super.prototype.over.call(this);
        //this.removeChild(new GameMain);
        // this.gun.addEvent(EVENT_FIRE, this.onFire, this)
        this.isStopPanel = true;
        SoundControl.getIns().stop(MUSIC_FIRE);
        this.gun.removeFromParent();
        this.controlGun.close();
        // console.log("jishiqian" + this.timer.running);
        // if (this.timer != null) {
        // this.timer.stop();
        this.timertime.stop();
        // this.timer = null;
        // }
        //console.log("jishihou" + this.timer.running);
        SoundControl.getIns().stop(MUSIC_BG);
        var bodys = this.world.p2World.bodies;
        for (var i = 0; i < bodys.length; i++) {
            var body = bodys[i];
            if (body.userData && body.userData.skin) {
                //if (body.userData["num"]) 
                {
                    var skin = body.userData.skin;
                    this.world.removeBodys.push(body);
                    skin.removeFromParent(true);
                }
            }
        }
    };
    GameControl.prototype.updateNumBody = function () {
    };
    GameControl.prototype.onHitImpact = function (evt) {
        // var ball: p2.Body;
        // if (evt.bodyA.userData && evt.bodyB.userData) {
        //     if (evt.bodyA.userData["ball"]) ball = evt.bodyA;
        //     if (evt.bodyB.userData["ball"]) ball = evt.bodyB;
        //     //与数字刚体
        //     if (evt.bodyA.userData["ball"] && evt.bodyB.userData["num"] || evt.bodyB.userData["ball"] && evt.bodyA.userData["num"]) {
        //         var vec = new Point(ball.velocity[0], ball.velocity[1]);
        //         var vecnum: number = Math.sqrt(vec.x * vec.x + vec.y * vec.y);
        //         console.log(vecnum);
        //         if (vecnum < 50) {
        //             this.setBallImpulse(ball);
        //         }
        //     }
        // }
    };
    //碰撞后事件
    GameControl.prototype.onHitBegin = function (evt) {
        var _this = this;
        var mother_ball;
        if (evt.bodyA.userData["motherhit"])
            mother_ball = evt.bodyA;
        if (evt.bodyB.userData["motherhit"])
            mother_ball = evt.bodyB;
        if (evt.bodyA.userData["dong"] && evt.bodyB.userData["motherhit"] || evt.bodyB.userData["dong"] && evt.bodyA.userData["motherhit"]) {
            if (mother_ball) {
                this.myScore -= 20; //白球进洞分数
                var str2 = "白球进洞-20分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = mother_ball.userData.skin;
                this.world.removeBodys.push(mother_ball);
                skin.removeFromParent(true);
                this.isHoled = true;
                // this.over();
            }
            if (this.isHoled) {
                this.timer = new egret.Timer(3000, 1);
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    //     console.log(this.time);
                    if (_this.time != 0) {
                        var whiteBall = new MImage("bai_png");
                        whiteBall.x = 320;
                        whiteBall.y = 850;
                        _this.addChild(whiteBall);
                        _this.white = whiteBall;
                        //  this.createMother();//两秒之后再添加一个
                        _this.createGameScene(); //添加拖动球
                    }
                }, this);
                this.timer.start();
                this.removeChild(this.gun);
                this.controlGun.close(); //关闭杆，线，围绕白球旋转
            }
        }
        //删除台球
        var taiqiu0;
        if (evt.bodyA.userData["taiqiu0"])
            taiqiu0 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu0"])
            taiqiu0 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu0"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu0"] && evt.bodyA.userData["dong"]) {
            console.log("00000");
            if (taiqiu0) {
                this.myScore += 10; //分数
                var str2 = "黄球进洞+10分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu0.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu0);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu1;
        if (evt.bodyA.userData["taiqiu1"])
            taiqiu1 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu1"])
            taiqiu1 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu1"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu1"] && evt.bodyA.userData["dong"]) {
            console.log("10000");
            if (taiqiu1) {
                this.myScore += 13; //分数
                var str2 = "蓝球进洞+13分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu1.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu1);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu2;
        if (evt.bodyA.userData["taiqiu2"])
            taiqiu2 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu2"])
            taiqiu2 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu2"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu2"] && evt.bodyA.userData["dong"]) {
            console.log("200000");
            if (taiqiu2) {
                this.myScore += 16; //分数
                var str2 = "绿球进洞+16分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu2.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu2);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu3;
        if (evt.bodyA.userData["taiqiu3"])
            taiqiu3 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu3"])
            taiqiu3 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu3"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu3"] && evt.bodyA.userData["dong"]) {
            console.log("300000");
            if (taiqiu3) {
                this.myScore += 19; //分数
                var str2 = "紫球进洞+19分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu3.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu3);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu4;
        if (evt.bodyA.userData["taiqiu4"])
            taiqiu4 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu4"])
            taiqiu4 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu4"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu4"] && evt.bodyA.userData["dong"]) {
            console.log("400000");
            if (taiqiu4) {
                this.myScore += 21; //分数
                var str2 = "黑紫球进洞+21分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu4.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu4);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu5;
        if (evt.bodyA.userData["taiqiu5"])
            taiqiu5 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu5"])
            taiqiu5 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu5"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu5"] && evt.bodyA.userData["dong"]) {
            console.log("500000");
            if (taiqiu5) {
                this.myScore += 11; //分数
                var str2 = "红球进洞+11分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu5.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu5);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu6;
        if (evt.bodyA.userData["taiqiu6"])
            taiqiu6 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu6"])
            taiqiu6 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu6"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu6"] && evt.bodyA.userData["dong"]) {
            console.log("600000");
            if (taiqiu6) {
                this.myScore += 12; //分数
                var str2 = "蓝球进洞+12分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu6.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu6);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu7;
        if (evt.bodyA.userData["taiqiu7"])
            taiqiu7 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu7"])
            taiqiu7 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu7"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu7"] && evt.bodyA.userData["dong"]) {
            console.log("700000");
            if (taiqiu7) {
                this.myScore += 14; //分数
                var str2 = "青球进洞+14分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu7.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu7);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu8;
        if (evt.bodyA.userData["taiqiu8"])
            taiqiu8 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu8"])
            taiqiu8 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu8"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu8"] && evt.bodyA.userData["dong"]) {
            console.log("800000");
            if (taiqiu8) {
                this.myScore += 15; //分数
                var str2 = "紫球进洞+15分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu8.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu8);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu9;
        if (evt.bodyA.userData["taiqiu9"])
            taiqiu9 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu9"])
            taiqiu9 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu9"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu9"] && evt.bodyA.userData["dong"]) {
            console.log("900000");
            if (taiqiu9) {
                this.myScore += 17; //分数
                var str2 = "草球进洞+17分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu9.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu9);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu10;
        if (evt.bodyA.userData["taiqiu10"])
            taiqiu10 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu10"])
            taiqiu10 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu10"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu10"] && evt.bodyA.userData["dong"]) {
            console.log("0100000");
            if (taiqiu10) {
                this.myScore += 10; //分数
                var str2 = "黑球进洞+10分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu10.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu10);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu11;
        if (evt.bodyA.userData["taiqiu11"])
            taiqiu11 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu11"])
            taiqiu11 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu11"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu11"] && evt.bodyA.userData["dong"]) {
            console.log("1100000");
            if (taiqiu11) {
                this.myScore += 12; //分数
                var str2 = "粉球进洞+12分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu11.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu11);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu12;
        if (evt.bodyA.userData["taiqiu12"])
            taiqiu12 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu12"])
            taiqiu12 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu12"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu12"] && evt.bodyA.userData["dong"]) {
            console.log("1200000");
            if (taiqiu12) {
                this.myScore += 15; //分数
                var str2 = "荧球进洞+15分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu12.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu12);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu13;
        if (evt.bodyA.userData["taiqiu13"])
            taiqiu13 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu13"])
            taiqiu13 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu13"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu13"] && evt.bodyA.userData["dong"]) {
            console.log("1300000");
            if (taiqiu13) {
                this.myScore += 19; //分数
                var str2 = "黄球进洞+19分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu13.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu13);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
        var taiqiu14;
        if (evt.bodyA.userData["taiqiu14"])
            taiqiu14 = evt.bodyA;
        if (evt.bodyB.userData["taiqiu14"])
            taiqiu14 = evt.bodyB;
        if (evt.bodyA.userData["taiqiu14"] && evt.bodyB.userData["dong"] || evt.bodyB.userData["taiqiu14"] && evt.bodyA.userData["dong"]) {
            console.log("1400000");
            if (taiqiu14) {
                this.myScore += 11; //分数
                var str2 = "蓝球进洞+11分";
                this.level = str2; //显示
                this.updateScore();
                this.updateLevel();
                this.timer = new egret.Timer(1000, 1); //显示一秒钟后消失
                this.timer.addEventListener(egret.TimerEvent.TIMER, function (e) {
                    _this.removeChild(_this.txtLevel);
                }, this);
                this.timer.start();
                this.addChild(this.txtLevel);
                var skin = taiqiu14.userData.skin;
                //移除障碍物刚体
                this.world.removeBodys.push(taiqiu14);
                //移除障碍物皮肤
                skin.removeFromParent(true);
            }
        }
    };
    GameControl.prototype.setBallImpulse = function (ball) {
        var x = Math.random() > 0.5 ? -5000 : 5000;
        var y = -5000 - (Math.random() * 2000);
        ball.applyImpulse([x, y], [0, 0]);
    };
    //分数
    GameControl.prototype.updateScore = function () {
        if (this.myScore < 0) {
            this.myScore = 0;
        }
        this.txtMyScore.text = "得分:" + this.myScore;
        this.txtMyScore.x = 400;
        this.txtMyScore.y = 75;
    };
    //提示面板
    GameControl.prototype.updateLevel = function () {
        this.txtLevel.text = this.level + "";
    };
    /**计时器 */
    GameControl.prototype.updateTime = function () {
        var _this = this;
        if (!this.isStopPanel) {
            //       console.log(this.time);
            var timer_1 = new egret.Timer(1000, 0);
            timer_1.addEventListener(egret.TimerEvent.TIMER, function (e) {
                _this.time--;
                _this.txtTime.text = "时间:" + _this.time;
                if (_this.time <= 0) {
                    _this.time = 0;
                    _this.txtTime.text = "时间:" + _this.time;
                    var a = String(_this.myScore);
                    var KVData = [{ key: "score", value: a }]; //获取玩家游戏中的分数
                    egretToWX.getInstance().storageUserData(KVData); //发送分说至排行榜
                    _this.updateScore();
                    timer_1.stop();
                    _this.over();
                    _this.controlGun.close();
                }
            }, this);
            timer_1.start();
        }
        this.creatGun();
    };
    GameControl.prototype.creatGun = function () {
        //创建炮
        var gun = new Gun;
        gun.addEvent(EVENT_FIRE, this.onFire, this);
        this.addChild(gun);
        this.gun = gun;
        gun.x = GameControl.motherBall.position[0];
        gun.y = GameControl.motherBall.position[1];
        //   console.log("cw");
    };
    /**创建刚体白球拖动 */
    GameControl.prototype.createGameScene = function () {
        var _this = this;
        // //转换比例
        var factor = 1;
        var p2World = new p2.World();
        //添加拖动事件
        this.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, moveBegin, this);
        this.stage.addEventListener(egret.TouchEvent.TOUCH_END, moveEnd, this);
        var data = this;
        var time = new egret.Timer(3000, 1);
        time.addEventListener(egret.TimerEvent.TIMER_COMPLETE, function (e) {
            data.stage.removeEventListener(egret.TouchEvent.TOUCH_END, moveEnd, data); //删除鼠标离开
            data.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, onMove, data); //删除鼠标移动
            data.stage.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, moveBegin, data);
            //    console.log(this.white.position);
            var x = _this.white.x;
            var y = _this.white.y;
            _this.removeChild(_this.white);
            _this.createMother();
            GameControl.motherBall.position[0] = x + 20;
            GameControl.motherBall.position[1] = y + 20;
            _this.creatGun();
            // data.gun.x = GameControl.motherBall.position[0];
            // data.gun.y = GameControl.motherBall.position[1];
            data.gun.showLine();
            data.controlGun.open();
        }, data);
        time.start();
        var offsetX, offsetY;
        var prePosX, prePosY;
        //鼠标点击
        function moveBegin(event) {
            time.stop();
            this.stage.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, moveBegin, this); //删除鼠标点击
            this.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, onMove, this);
            prePosX = event.stageX;
            prePosY = event.stageY;
            //this.Qui.type = p2.Body.KINEMATIC;
        }
        //鼠标移动。拖动白球
        function onMove(event) {
            offsetX = event.stageX - prePosX;
            offsetY = event.stageY - prePosY;
            // GameControl.motherBall.position[0] += offsetX / factor;
            // GameControl.motherBall.position[1] += offsetY / factor;
            this.white.x += offsetX / factor;
            this.white.y += offsetY / factor;
            //  console.log(this.Qui.sleepState);
            prePosX = event.stageX;
            prePosY = event.stageY;
            // GameControl.motherBall.type=p2.Body.SLEEPY;
            // GameControl.motherBall.sleepTimeLimit=3000;
            // rectDisplayObject.x = event.stageX;
            // rectDisplayObject.y = event.stageY;
        }
        //鼠标离开
        function moveEnd() {
            var _this = this;
            this.gun.showLine();
            var time = new egret.Timer(100, 1);
            time.addEventListener(egret.TimerEvent.TIMER_COMPLETE, function (e) {
                var x = _this.white.x;
                var y = _this.white.y;
                _this.removeChild(_this.white);
                _this.createMother();
                GameControl.motherBall.position[0] = x + 20;
                GameControl.motherBall.position[1] = y + 20;
                _this.creatGun();
                _this.controlGun.open();
            }, data);
            time.start();
            this.stage.removeEventListener(egret.TouchEvent.TOUCH_END, moveEnd, this); //删除鼠标离开
            this.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, onMove, this); //删除鼠标移动
            GameControl.motherBall.type = p2.Body.DYNAMIC;
            //this.controlGun.open();//开启杆，线，围绕白球旋转
        }
    };
    GameControl.prototype.startBackFun = function (pos) {
        this.gun.showLine();
        this.controlGun.close();
        this.controlMove(pos);
    };
    /**找到最近的球 */
    GameControl.prototype.getRaycastProps = function (startx, starty, endx, endy) {
        var mindis = 30;
        var min = 1000;
        var nearestBall = null;
        for (var i = 0; i < this.my_ball.length; ++i) {
            var ball = this.my_ball[i];
            var zuobiao1 = new egret.Point(this.gun.x, this.gun.y);
            var zuobiao2 = new egret.Point(this.my_ball[i].position[0], this.my_ball[i].position[1]);
            var juli = egret.Point.distance(zuobiao1, zuobiao2);
            var dis = py2Obj.MathUtils.getDistanceBetweenPointAndLine(startx, starty, endx, endy, ball.position[0], ball.position[1], this);
            //   console.log("XXXXXXXXXXXXXXXXXXXX" + dis);
            if (dis < 30) {
                if (juli < min) {
                    min = juli;
                    nearestBall = ball;
                }
            }
        }
        if (nearestBall != null) {
            console.log("mindis" + mindis + "zuobiao" + nearestBall.position[0] + "," + nearestBall.position[1]);
        }
        return nearestBall;
    };
    GameControl.prototype.controlMove = function (posMove) {
        var pos = new egret.Point(-(posMove.x - this.gun.x), -(posMove.y - this.gun.y));
        //traceSimple(pos.x,pos.y);
        this.gun.updatePos(pos);
        var ptFrom = { x: this.gun.x, y: this.gun.y };
        var ptTo = { x: 0, y: 0 };
        var angle = Math.atan2(pos.x, pos.y);
        ptTo = { x: ptFrom.x + Math.sin(angle) * 1000, y: ptFrom.y + Math.cos(angle) * 1000 };
        var ray = new p2.Ray({ from: [ptFrom.x, ptFrom.y], to: [ptTo.x, ptTo.y], mode: p2.Ray.CLOSEST });
        var nearstBall = this.getRaycastProps(ptFrom.x, ptFrom.y, ptTo.x, ptTo.y);
        if (nearstBall != null) {
            var nextPos = { x: ptFrom.x, y: ptFrom.y };
            var dis = 1000;
            var bool = false;
            while (dis > 30) {
                if (egret.Point.distance(egret.Point.create(ptFrom.x, ptFrom.y), egret.Point.create(nextPos.x, nextPos.y)) > 1100) {
                    bool = true;
                    break;
                }
                nextPos = { x: nextPos.x + ray.direction[0] * 8.333333446434443, y: nextPos.y + ray.direction[1] * 8.333333446434443 };
                dis = Math.sqrt((nextPos.x - nearstBall.position[0]) * (nextPos.x - nearstBall.position[0]) + (nextPos.y - nearstBall.position[1]) * (nextPos.y - nearstBall.position[1]));
            }
            var ptIns = { x: nextPos.x, y: nextPos.y };
            this.shape.graphics.clear();
            //  var shape = new egret.Shape();
            //  this.shape.graphics.lineStyle(2, 0x00ff00);
            //出发的线
            // this.shape.graphics.moveTo(ptFrom.x, ptFrom.y);
            // this.shape.graphics.lineTo(ptTo.x, ptTo.y);
            if (bool == false) {
                //预测碰撞位置 
                this.shape.graphics.lineStyle(3, 0xf8f8ff);
                this.shape.graphics.moveTo(GameControl.motherBall.position[0], GameControl.motherBall.position[1]);
                this.shape.graphics.lineTo(ptIns.x, ptIns.y);
                this.shape.graphics.drawCircle(ptIns.x, ptIns.y, 15);
                //球心联系
                this.shape.graphics.moveTo(ptIns.x, ptIns.y);
                this.shape.graphics.lineTo(nearstBall.position[0], nearstBall.position[1]);
                //  console.log("|||||||||||||||**************" + ptIns1.x +"," +ptIns1.y + "V" + + ptIns2.x +"," +ptIns2.y );
                var rayOut = p2.vec2.clone([0, 0]);
                var rayDir = p2.vec2.clone([0, 0]);
                p2.vec2.normalize(rayDir, [ptFrom.x - ptTo.x, ptFrom.y - ptTo.y]);
                var rayNor = p2.vec2.clone([0, 0]);
                p2.vec2.normalize(rayNor, [ptIns.y - nearstBall.position[1], -ptIns.x + nearstBall.position[0]]);
                p2.vec2.reflect(rayOut, rayDir, rayNor);
                //   console.log(rayOut[0] + "{{{{{{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}}}}" + rayOut[1]);
                //垂线
                this.shape.graphics.moveTo(ptIns.x, ptIns.y);
                if (ptIns.x >= nearstBall.position[0]) {
                    //       console.log("zheng zheng zheng right");
                    this.shape.graphics.lineTo(ptIns.x + rayNor[0] * 50, ptIns.y + rayNor[1] * 50);
                }
                else if (ptIns.x < nearstBall.position[0]) {
                    //     console.log("fu fu fu left");
                    this.shape.graphics.lineTo(ptIns.x + rayNor[0] * -50, ptIns.y + rayNor[1] * -50);
                }
            }
            //反射线
            //    this.shape.graphics.moveTo(ptIns.x, ptIns.y);
            // this.shape.graphics.lineTo(ptIns.x +rayOut[0]*500 ,ptIns.y +rayOut[1] *500 );
            //   this.shape.graphics.lineStyle(2, 0x0000ff);
            //入射线
            //  this.shape.graphics.moveTo(ptIns.x, ptIns.y);
            //  this.shape.graphics.lineTo(ptIns.x +ray.direction[0] *100 ,ptIns.y +ray.direction[1] *100 );
            //   this.shapeendFill();
            this.shape.graphics.endFill();
            this.addChild(this.shape);
        }
        else {
            this.shape.graphics.clear();
        }
    };
    GameControl.prototype.endBackFun = function (posEnd) {
        var pos = new egret.Point(posEnd.x - this.gun.x, posEnd.y - this.gun.y);
        var angle = Math.atan2(pos.x, pos.y);
        var dis = 10000;
        var x = Math.ceil(Math.sin(angle) * dis);
        var y = Math.ceil(Math.cos(angle) * dis);
        this.vec = new egret.Point(x, y);
        this.gun.hideLine();
        this.gun.fire();
        this.shape.graphics.clear();
        this.controlGun.close();
    };
    /**设置力 */
    GameControl.prototype.setForce = function (x, y) {
        GameControl.motherBall.fixedX = false;
        GameControl.motherBall.fixedY = false;
        GameControl.motherBall.applyImpulse([x, y], [0, 0]);
    };
    /**设置球的位置 */
    GameControl.prototype.setPostion = function (x, y) {
        GameControl.motherBall.position = [x, y];
    };
    /**给球力 */
    GameControl.prototype.send = function (x, y, forcex, forcey) {
        GameControl.motherBall.type = 1;
        GameControl.motherBall.velocity = [0, 0];
        GameControl.motherBall.damping = 0.5;
        this.doMaterial(GameControl.motherBall);
        this.setPostion(x, y);
        this.setForce(forcex, forcey);
    };
    /**开火 */
    GameControl.prototype.onFire = function (e) {
        // var i = 0;
        // var arr = [];
        // var brr = [];
        if (Gun.distance >= 165) {
            Gun.distance = 165;
            this.send(this.gun.x, this.gun.y, -(this.vec.x * 0.007 * Gun.distance), -(this.vec.y * 0.007 * Gun.distance));
        }
        else {
            this.send(this.gun.x, this.gun.y, -(this.vec.x * 0.007 * Gun.distance), -(this.vec.y * 0.007 * Gun.distance));
        }
        //    console.log(Gun.distance + " ++++++");
        // this.timertime = new egret.Timer(3000, 0);
        // this.timertime.addEventListener(egret.TimerEvent.TIMER, e => {
        //     var a: number = Math.round(GameControl.motherBall.position[0]);
        //     var b: number = Math.round(GameControl.motherBall.position[1]);
        //     arr.push(a);
        //     brr.push(b);
        //     var c = Math.abs(arr[i - 1] - arr[i]);
        //     var d = Math.abs(brr[i - 1] - brr[i]);
        //     if (c < 10 && d < 10) {
        //         console.log("相等了");
        //         this.gun.x = arr[i];
        //         this.gun.y = brr[i];
        //         console.log("枪的位置" + this.gun.x, this.gun.y);
        //         console.log("母球的位置" + GameControl.motherBall.position);
        //         this.gun.showLine();
        //         this.controlGun.open();
        //     }
        //     i++;
        // }, this);
        // this.timertime.start();
        // this.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.controlGanMove, this);
    };
    GameControl.prototype.ganShow = function () {
        var _this = this;
        var i = 0;
        var arr = [];
        var brr = [];
        this.timertime = new egret.Timer(3000, 0);
        this.timertime.addEventListener(egret.TimerEvent.TIMER, function (e) {
            var a = Math.round(GameControl.motherBall.position[0]);
            var b = Math.round(GameControl.motherBall.position[1]);
            arr.push(a);
            brr.push(b);
            var c = Math.abs(arr[i - 1] - arr[i]);
            var d = Math.abs(brr[i - 1] - brr[i]);
            if (c < 10 && d < 10) {
                //    console.log("相等了");
                _this.gun.x = arr[i];
                _this.gun.y = brr[i];
                //        console.log("枪的位置" + this.gun.x, this.gun.y);
                //       console.log("母球的位置" + GameControl.motherBall.position);
                _this.gun.showLine();
                _this.controlGun.open();
            }
            i++;
        }, this);
        this.timertime.start();
    };
    /**与加碰撞产生新球 */
    GameControl.prototype.createNewBall = function (ball) {
        // var newBall = this.createBall();
        // newBall.position = [ball.position[0], ball.position[1]];
        // newBall.mass = 100;
        // this.setBallImpulse(newBall);
    };
    /** 距离右边的距离*/
    GameControl.prototype.getRight = function (distance) {
        return GameData.stageWidth - distance;
    };
    /** 距离右边的距离*/
    GameControl.prototype.getBottom = function (distance) {
        return GameData.stageHeight - distance;
    };
    /** 传入宽后居中距离*/
    GameControl.prototype.getCenterX = function (skinWidth) {
        return (GameData.stageWidth - skinWidth) >> 1;
    };
    /**设置与球的碰撞弹性 */
    GameControl.prototype.doMaterial = function (ball) {
        var world = this.world;
        var bodys = world.p2World.bodies;
        var l = bodys.length;
        for (var i = 0; i < l; i++) {
            var body = bodys[i];
            if (body.userData["hit"] || body.userData["motherhit"] || body.userData["bianhit"]) {
                this.setMaterial(ball, body);
            }
        }
    };
    /** 设置刚体碰撞的弹性*/
    GameControl.prototype.setMaterial = function (body1, body2) {
        var materialA = this.material;
        var materialB = this.material;
        body1.shapes[0].material = materialA;
        body2.shapes[0].material = materialB;
        var roleAndStoneMaterial = new p2.ContactMaterial(materialA, materialB, { restitution: 1, friction: 0 }); //弹性，摩擦力
        this.world.p2World.addContactMaterial(roleAndStoneMaterial);
    };
    /** 创建底座三角形刚体*/
    GameControl.prototype.createBottom = function () {
        var world = this.world;
        var h = 59, w = 520; //三角形高与宽
        var bottom = world.createConvexBodyShape([[0, h], [w / 2, 0], [w, h]]);
        // var skin:MImage=this.createSkin("bottom_png");
        // bottom.userData.skin=skin;
        //world.drawSkin(bottom);
        bottom.position = [this.getCenterX(0), this.getBottom(h / 2) + 10];
        bottom.type = p2.Body.KINEMATIC;
        this.setAndBallHit(bottom);
        var skin = this.createSkin("bottom_png");
        skin.x = this.getCenterX(0) - 5;
        skin.y = this.getBottom(h / 2);
        this.addChild(skin);
    };
    /**设置属性后就可以与球碰撞 */
    GameControl.prototype.setAndBallHit = function (body) {
        var shape = body.shapes[0];
        shape.collisionMask = 3; //010与001为0，010与110为1
    };
    /** 创建球刚体*/
    GameControl.prototype.createBall = function () {
        var world = this.world;
        var skin = this.createSkin("ball_png");
        var body = world.createCircleBodyShape(skin.width >> 1);
        body.userData.skin = skin;
        body.userData["ball"] = true;
        body.mass = 0; //质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
        //body.gravityScale=0;
        body.damping = 0.5;
        var shape = body.shapes[0];
        shape.collisionGroup = 2; //010与001为0，010与110为1
        // shape.collisionMask=2;
        //trace(shape.collisionGroup,shape.collisionMask)
        return body;
    };
    /**创建静态刚体 */
    GameControl.prototype.createBody2 = function (name, shapeType, type) {
        if (shapeType === void 0) { shapeType = SHAPE.rect; }
        if (type === void 0) { type = p2.Body.KINEMATIC; }
        var world = this.world;
        var skin = this.createSkin(name);
        var body;
        if (shapeType == SHAPE.rect)
            body = world.createBoxBodyShape(skin.width, skin.height, type);
        else if (shapeType == SHAPE.circle)
            body = world.createCircleBodyShape(skin.width >> 1, type);
        body.userData.skin = skin;
        body.userData["bianhit"] = true;
        //this.doMaterial(body);
        this.setAndBallHit(body);
        return body;
    };
    /** 创建刚体*/
    GameControl.prototype.createBody = function (name, shapeType, type) {
        if (shapeType === void 0) { shapeType = SHAPE.circle; }
        if (type === void 0) { type = p2.Body.DYNAMIC; }
        var world = this.world;
        var skin = this.createSkin(name);
        var body;
        if (shapeType == SHAPE.rect)
            body = world.createBoxBodyShape(skin.width, skin.height, type);
        else if (shapeType == SHAPE.circle)
            body = world.createCircleBodyShape(skin.width >> 1, type);
        body.userData.skin = skin;
        this.doMaterial(body);
        this.setAndBallHit(body);
        return body;
    };
    /** 创建带数字刚体*/
    GameControl.prototype.createNumBody = function () {
        //     var names: string[] = this.names;
        //     var name: string = names[Math.floor(Math.random() * names.length)];
        //     if (this.gun.bulletMax < 5) {//子弹小于5个时增加子弹的概率
        //         if (Math.random() < 0.2) name = ICON_ADD;
        //     } else if (this.gun.bulletMax > 20) {//子弹大于20后减少增加子弹的概率
        //         if (name == ICON_ADD && Math.random() < 0.8) name = "circle1_png";
        //     }
        //   //  var shape = name.split("rect").length == 2 ? SHAPE.rect : SHAPE.circle;
        // var body = this.createBody(name,shape);
        //      return body;
    };
    /** 创建皮肤*/
    GameControl.prototype.createSkin = function (name) {
        var skin = new NumImage(name);
        skin.x = -500; //避免在一出现的时候会在左上角闪现
        skin.setAnchorCenter();
        this.addChild(skin);
        return skin;
    };
    GameControl.prototype.loopP2World = function () {
        // var bodys = this.world.p2World.bodies;
        // //traceSimple("bodys",bodys.length);
        // var l: number = bodys.length;
        // for (var i: number = 0; i < l; i++) {
        //     var body: p2.Body = bodys[i];
        //     if (body.userData && body.userData.skin) {
        //         if (body.userData["ball"]) {
        //             var vec = new Point(body.velocity[0], body.velocity[1]);
        //             var vecnum: number = Math.sqrt(vec.x * vec.x + vec.y * vec.y);
        //             if (vecnum < 1) {
        //                 console.log(vecnum);
        //                 this.setBallImpulse(body);
        //             }
        //         }
        //     }
        // }
    };
    GameControl.prototype.loop = function (n) {
        var skins = this.removeSkins;
        // traceSimple(skins.length)
        for (var i = 0; i < skins.length; i++) {
            var skin = skins[i];
            skin.removeFromParent(true);
        }
        // if (this.ballNum == 0) {
        //     this.nextLevel();
        // }
        return true;
    };
    GameControl.prototype.nextLevel = function () {
        //   this.ballNum = this.gun.bulletMax;
        this.removeSkins.length = 0;
        this.updateNumBody();
        this.gun.initNum();
    };
    return GameControl;
}(moon.BasicGamePanel));
__reflect(GameControl.prototype, "GameControl");
/**分数图标*/
var NumImage = (function (_super) {
    __extends(NumImage, _super);
    // private _value: number = -1;
    // private txt: TextField;
    function NumImage(skinName) {
        if (skinName === void 0) { skinName = "num"; }
        return _super.call(this, skinName) || this;
    }
    Object.defineProperty(NumImage.prototype, "imageName", {
        // public initNum(v: number): void {
        //     this.txt = this.createText(0, 0);
        //     if (this.skinName == ICON_ADD) {
        //         this._value = 1;
        //     } else {
        //         this.value = v;
        //     }
        // }
        // protected createText(x: number = 0, y: number = 0, s: string = ""): TextField {
        //     var text: TextField = (new moon.Label).textField;
        //     text.x = x; text.y = y; text.text = s;
        //     this.addChild(text);
        //     return text;
        // }
        // set value(v: number) {
        //     this._value = v;
        //     this.txt.text = String(v);
        //     this.txt.textColor = 0;
        //     if (this.parent != null) {
        //         Layout.getIns().setCenterXByPanent(this.txt);
        //         Layout.getIns().setCenterYByPanent(this.txt);
        //     }
        // }
        // get value(): number {
        //     return this._value;
        // }
        get: function () {
            return this.skinName;
        },
        enumerable: true,
        configurable: true
    });
    return NumImage;
}(MImage));
__reflect(NumImage.prototype, "NumImage");
/**枪*/
var Gun = (function (_super) {
    __extends(Gun, _super);
    function Gun() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        //  private line: MImage;
        _this.bulletMax = 3;
        return _this;
    }
    Gun.prototype.render = function () {
        // var motherBall: GameControl = new GameControl;
        var gun = new MImage("cue_png");
        gun.anchorOffsetX = gun.width >> 1;
        this.addChild(gun);
        this.gun = gun;
        // var numBg: MImage = new MImage("numBg_png");
        // numBg.setAnchorCenter();
        // this.addChild(numBg);
        // var line: MImage = new MImage("line_png");
        // line.anchorOffsetX = line.width >> 1;
        // this.line = line;
        // this.txtNum = this.createText(0, 0, "");
        // this.bullet = this.bulletMax;
        // this.updateNum(this.bullet)
    };
    //画线
    Gun.prototype.onAddToStage_wire = function () {
        // //画线
        this.shp = new egret.Shape();
        this.shp.graphics.lineStyle(3, 0xC0C0C0); //宽度设置为 2，颜色设置为 0x00ff00 
        this.shp.graphics.moveTo(this.gun.x, this.gun.y); //moveTo 来设定线条的起始点
        this.shp.graphics.lineTo(0, 0); // lineTo 来设定线条的终点
        this.shp.graphics.endFill();
        this.addChild(this.shp);
    };
    //旋转
    // public updatePos(pos: egret.Point): void {
    //     if (-pos.y > this.gun.y) {
    //         this.shp.graphics.lineTo(0, -pos.y);
    //         //    console.log(this.shp.scaleY);
    //         if (this.shp.height > -pos.y) {
    //             this.removeChild(this.shp);
    //             this.shp = new egret.Shape();
    //             // this.shp.alpha = 0;////透明度
    //             var shp: egret.Shape = new egret.Shape();
    //             this.shp.graphics.lineStyle(3, 0x00ff00);
    //             this.shp.graphics.moveTo(this.gun.x, this.gun.y);
    //             this.shp.graphics.lineTo(0, -pos.y);
    //             this.shp.graphics.endFill();
    //             this.addChild(this.shp);
    //         }
    //     }
    //     if (-pos.y < this.gun.y) {
    //         this.shp.graphics.lineTo(0, pos.y);
    //         if (this.shp.height > -pos.y) {
    //             this.removeChild(this.shp);
    //             this.shp = new egret.Shape();
    //             // this.shp.alpha = 0;////透明度
    //             var shp: egret.Shape = new egret.Shape();
    //             this.shp.graphics.lineStyle(3, 0x00ff00);
    //             this.shp.graphics.moveTo(this.gun.x, this.gun.y);
    //             this.shp.graphics.lineTo(0, pos.y);
    //             this.shp.graphics.endFill();
    //             this.addChild(this.shp);
    //         }
    //     }
    //     var r: number = -Math.atan2(pos.x, pos.y) * 180 / Math.PI;
    //     this.gun.rotation = r;
    //     this.shp.rotation = r;
    // }
    Gun.prototype.restart = function () {
        // this.bulletMax = 1;
        // this.initNum();
    };
    Gun.prototype.updatePos = function (pos) {
        Gun.distance = Math.sqrt(this.gun.x * this.gun.x + this.gun.y * this.gun.y);
        //    console.log("pos!!!" + Gun.distance);
        var r = -Math.atan2(pos.x, pos.y) * 180 / Math.PI;
        // console.log("pos"+pos.x,pos.y);
        //  if (-pos.y > this.gun.y) {
        //     this.shp.graphics.lineTo(0, -pos.y);
        //     //    console.log(this.shp.scaleY);
        //     if (this.shp.height > -pos.y) {
        //         this.removeChild(this.shp);
        //         this.shp = new egret.Shape();
        //         // this.shp.alpha = 0;////透明度
        //         var shp: egret.Shape = new egret.Shape();
        //         this.shp.graphics.lineStyle(3, 0x00ff00);
        //         this.shp.graphics.moveTo(this.gun.x, this.gun.y);
        //         this.shp.graphics.lineTo(0, -pos.y);
        //         this.shp.graphics.endFill();
        //         this.addChild(this.shp);
        //     }
        // }
        // if (-pos.y < this.gun.y) {
        //     this.shp.graphics.lineTo(0, pos.y);
        //     if (this.shp.height > -pos.y) {
        //         this.removeChild(this.shp);
        //         this.shp = new egret.Shape();
        //         // this.shp.alpha = 0;////透明度
        //         var shp: egret.Shape = new egret.Shape();
        //         this.shp.graphics.lineStyle(3, 0x00ff00);
        //         this.shp.graphics.moveTo(this.gun.x, this.gun.y);
        //         this.shp.graphics.lineTo(0, pos.y);
        //         this.shp.graphics.endFill();
        //         this.addChild(this.shp);
        //     }
        // }
        //  this.line.rotation = r;
        this.gun.rotation = 180 + r;
        //this.shp.rotation =r;
        this.gun.x = -pos.x;
        this.gun.y = -pos.y;
        // var distance_x,distance_y,distance;
        // distance_x=Math.abs(this.gun.x-GameControl.motherBall.position[0]);
        //    console.log("枪x" + this.gun.x + "母球x" + GameControl.motherBall.position[0]);
        // distance_y=Math.abs(this.gun.y-GameControl.motherBall.position[1]);
        //  console.log("y距离"+distance_y+"枪y"+this.gun.y+"母球y"+GameControl.motherBall.position[1]);
        // distance=Math.sqrt(distance_x*distance_x+distance_y*distance_y);
        // console.log("pos!!!"+distance);
        // this.gun.rotation = r; 
        // this.line.rotation =180+r;
    };
    Gun.prototype.initNum = function () {
        // this.bullet = this.bulletMax;
        // this.updateNum(this.bullet)
    };
    Gun.prototype.showLine = function () {
        //  this.addChildAt(this.line, 0);
        this.addChildAt(this.gun, 0);
        // this.gun.removeFromParent();
        // this.onAddToStage_wire();
    };
    Gun.prototype.hideLine = function () {
        //  this.line.removeFromParent();
        this.gun.removeFromParent();
        // this.removeChild(this.shp);
    };
    Gun.prototype.updateNum = function (value) {
        // this.txtNum.text = String(value);
        // this.txtNum.anchorOffsetX = this.txtNum.width >> 1;
        // this.txtNum.anchorOffsetY = this.txtNum.height >> 1;
    };
    Gun.prototype.fire = function () {
        //   if (this.bullet > 0) {
        this.updateNum(--this.bullet);
        Tween.get(this.gun).to({ scaleY: 0.6 }, 100).to({ scaleY: 1 }, 100);
        this.dispEvent(EVENT_FIRE);
        //  setTimeout(this.fire.bind(this), 300);
        SoundControl.getIns().play(MUSIC_FIRE);
        //  }
    };
    return Gun;
}(moon.BasicView));
__reflect(Gun.prototype, "Gun");
var CONST_SCORE_HIGHEST = "playBall score highest"; //最高分数
var GamePanel = { rank: null, over: null, game: null };
var GameMain = (function (_super) {
    __extends(GameMain, _super);
    function GameMain() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    GameMain.prototype.initView = function () {
        //this.createBgGradientFill();
        //面板－主要逻辑处理
        this.panelGame = new GameControl();
        this.panelGame.addEvent(MoonEvent.OVER, this.onOver, this);
        this.addChild(this.panelGame);
        GamePanel.game = this.panelGame;
        // //面板－设置
        // this.panelSet = new GameSet;
        // this.panelSet.addEvent(MoonEvent.PLAY, this.onSetHandler, this);
        // this.panelSet.addEvent(MoonEvent.CHANGE, this.onSetHandler, this);
        //面板－开始
        this.panelStart = new Gamebegin;
        this.panelStart.addEvent(moon.MoonEvent.START, this.start, this);
        this.addChild(this.panelStart);
        //面板－结束
        this.panelOver = new GameOver;
        this.panelOver.addEvent(moon.MoonEvent.START, this.start, this);
        //this.addChild(this.panelOver);
        //按钮－设置
        this.setBtn = new moon.SetButton;
        this.setBtn.x = 100;
        this.setBtn.y = 100;
        this.setBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.openSetPanel, this);
        // this.addChild(this.setBtn);
        //读取历史最高分
        GameData.scoreHighest = Number(moon.BasicGameStorage.localRead(CONST_SCORE_HIGHEST));
    };
    return GameMain;
}(moon.BasicGameMain));
__reflect(GameMain.prototype, "GameMain");
/**开始界面*/
var GameStart = (function (_super) {
    __extends(GameStart, _super);
    function GameStart() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    GameStart.prototype.initView = function () {
        this.createImageBg("beijing_png");
        var btn = new MButton(new MImage("kaishi_png"), new MImage("kaishi_png"));
        this.addChild(btn);
        btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
        btn.x = 350;
        btn.y = 800;
    };
    return GameStart;
}(moon.BasicGameStart));
__reflect(GameStart.prototype, "GameStart");
/**游戏结束 */
var GameOver = (function (_super) {
    __extends(GameOver, _super);
    function GameOver() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.layout = Layout.getIns();
        return _this;
    }
    GameOver.prototype.initView = function () {
        this.gameRank = new GameRank();
        GamePanel.rank = this.gameRank;
        GamePanel.over = this;
        this.layout.setStageWH(this.stageWidth, this.stageHeight);
        this.createImageBg("xiaoguotu_png");
        this.btnRestart = this.createMButton("kaishi_png", 336, 739);
        this.txtScore = this.createText(325, 310);
        //排行榜按钮
        this.buttonr = new MButton(new MImage("paihang_bang_png"), new MImage("paihang_bang_png"));
        this.addChild(this.buttonr);
        this.buttonr.addEventListener(egret.TouchEvent.TOUCH_TAP, this.button, this);
        this.buttonr.x = 10;
        this.buttonr.y = 730;
        //更多游戏按钮
        this.More_Games = new MButton(new MImage("more_png"), new MImage("more_png"));
        this.addChild(this.More_Games);
        this.More_Games.addEventListener(egret.TouchEvent.TOUCH_TAP, this.share, this);
        this.More_Games.x = 3;
        this.More_Games.y = 860;
    };
    // //更多游戏监听事件
    // private buttappMore() {
    // 	//获取共享森林连接
    // //	window.open("http://www.yxsl999.com/index.html");
    // 	this.url = "http://www.yxsl999.com/index.html";
    // }
    //自制转发
    GameOver.prototype.share = function () {
        console.log("share");
        platform.share(); //转发
    };
    /**排行榜监听事件 */
    GameOver.prototype.button = function () {
        egretToWX.getInstance().setGameHandle(this);
        //调去egretToWX脚本
        egretToWX.getInstance().paihangBtnClick();
    };
    GameOver.prototype.createMButton = function (name, x, y) {
        var btn = this.createSkinBtn(name, name);
        btn.x = x;
        btn.y = y;
        return btn;
    };
    GameOver.prototype.createSkinBtn = function (value1, value2) {
        var skin = new Scale9Image(value1);
        var skin2 = new Scale9Image(value2);
        skin2.alpha = 0.5;
        var btn = new MButton(skin, skin2);
        btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);
        this.addChild(btn);
        return btn;
    };
    GameOver.prototype.onClick = function (e) {
        if (e.currentTarget == this.btnRestart) {
            //this.dispEvent(MoonEvent.START);
            // this.dispEvent(MoonEvent.STOP);
            //this.addChild(this.gameStart);
            // this.removeChild(new GameMain);
            console.log("重新开始啦啊啊啊啊");
            this.addChild(new GameMain);
            //this.removeChild(this.buttonr);
            this.buttonr.touchEnabled = false; //
            this.More_Games.touchEnabled = false;
            this.btnRestart.touchEnabled = false;
        }
        else if (e.currentTarget == this.btnScore) {
            //	platform.submitScore(GameData.score,this.callback,this);
        }
        else if (e.currentTarget == this.btnRank) {
            this.addChild(this.gameRank);
            this.gameRank.updateScore();
        }
        SoundControl.getIns().play(MUSIC_CLICK_BTN);
    };
    /**提交分数返回函数 */
    GameOver.prototype.callback = function (obj) {
        console.log("代码:" + obj.code + ",消息:" + obj.message + ",数据:" + obj.data);
        if (obj.code == 10000) {
            console.log("上传成功");
            alertAuto("分数提交成功");
        }
        else {
            console.log("上传失败");
        }
    };
    GameOver.prototype.update = function (data) {
        GameData.score = data["score"];
        if (GameData.score > GameData.scoreHighest) {
            GameData.scoreHighest = GameData.score;
            moon.BasicGameStorage.localWrite(CONST_SCORE_HIGHEST, GameData.scoreHighest.toString());
        }
        this.txtScore.text = String(GameData.score);
        //this.txtScoreMax.text=String(GameData.scoreHighest);
    };
    return GameOver;
}(moon.BasicGameOver));
__reflect(GameOver.prototype, "GameOver");
/**分数排行*/
var GameRank = (function (_super) {
    __extends(GameRank, _super);
    function GameRank() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    GameRank.prototype.updateScore = function () {
        //platform.getRank(this.update,this);
    };
    /**查看排行榜返回函数 */
    GameRank.prototype.update = function (obj) {
        console.log("代码:" + obj.code + ",消息:" + obj.message + ",数据:" + obj.data);
        var _this = GamePanel.rank;
        if (obj.code == 10000) {
            console.log("获取成功");
            var data = obj.data;
            var len = data.length;
            var myRank = -1;
            for (var i = 0; i < len; i++) {
                //this.txtRank.text+=("积分:" + data[i].score + ",排名:" + data[i].rank+"\n");
                var score = data[i].score;
                console.log(i, score, _this.max);
                if (i < _this.max) {
                    var item = _this.items[i];
                    item.txtScore.text = score;
                    console.log("item", item.txtScore.text, score);
                }
                if (i < len - 1) {
                    var next = Number(data[i + 1].score);
                    score = Number(score);
                    console.log(GameData.score, next, score);
                    if (GameData.score == score) {
                        myRank = i + 1;
                    }
                    else if (GameData.score > next && GameData.score <= score) {
                        myRank = i + 2;
                    }
                    else if (GameData.score >= data[0].score) {
                        myRank = 1;
                    }
                    else if (GameData.score <= data[len - 1].score) {
                        myRank = len;
                    }
                }
            }
            if (_this.txtRank) {
                if (myRank > 0)
                    _this.txtRank.text = "你本次得" + GameData.score + "分，排在第" + myRank + "名。";
                else
                    _this.txtRank.text = "未上榜";
            }
        }
        else {
            console.log("获取失败");
        }
    };
    return GameRank;
}(moon.BasicGameRank));
__reflect(GameRank.prototype, "GameRank");
/**分数设置*/
var GameSet = (function (_super) {
    __extends(GameSet, _super);
    function GameSet() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return GameSet;
}(moon.BasicGameSet));
__reflect(GameSet.prototype, "GameSet");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var Main = (function (_super) {
    __extends(Main, _super);
    function Main() {
        var _this = _super.call(this) || this;
        _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
        return _this;
    }
    Main.prototype.onAddToStage = function (event) {
        //初始化moon组件
        moon.GameMoon.init(this.stage);
        moon.GameData.version = moon.Const.VER_RELEASE;
        egret.lifecycle.addLifecycleListener(function (context) {
            // custom lifecycle plugin
            context.onUpdate = function () {
            };
        });
        egret.lifecycle.onPause = function () {
            egret.ticker.pause();
        };
        egret.lifecycle.onResume = function () {
            egret.ticker.resume();
        };
        this.runGame().catch(function (e) {
            console.log(e);
        });
    };
    Main.prototype.runGame = function () {
        return __awaiter(this, void 0, void 0, function () {
            var result, userInfo;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.loadResource()];
                    case 1:
                        _a.sent();
                        this.createGameScene();
                        return [4 /*yield*/, RES.getResAsync("description_json")];
                    case 2:
                        result = _a.sent();
                        return [4 /*yield*/, platform.login()];
                    case 3:
                        _a.sent(); //加载
                        return [4 /*yield*/, platform.showShareMenu()];
                    case 4:
                        _a.sent(); //系统转发
                        return [4 /*yield*/, platform.getUserInfo()];
                    case 5:
                        userInfo = _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    Main.prototype.loadResource = function () {
        return __awaiter(this, void 0, void 0, function () {
            var loadingView, e_1;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        _a.trys.push([0, 3, , 4]);
                        loadingView = new LoadingUI();
                        this.stage.addChild(loadingView);
                        return [4 /*yield*/, RES.loadConfig("resource/default.res.json", "resource/")];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, RES.loadGroup("preload", 0, loadingView)];
                    case 2:
                        _a.sent();
                        this.stage.removeChild(loadingView);
                        return [3 /*break*/, 4];
                    case 3:
                        e_1 = _a.sent();
                        console.error(e_1);
                        return [3 /*break*/, 4];
                    case 4: return [2 /*return*/];
                }
            });
        });
    };
    //自制转发
    Main.prototype.share = function () {
        console.log("share");
        platform.share(); //转发
    };
    /**
     * 创建游戏场景
     * Create a game scene
     */
    Main.prototype.createGameScene = function () {
        this.addChild(new GameMain);
    };
    return Main;
}(egret.DisplayObjectContainer));
__reflect(Main.prototype, "Main");
/**
 * 声音控制单例管理类
 * 创建时间2017/12/5
 * @author vinson
 */
var SoundControl = (function (_super) {
    __extends(SoundControl, _super);
    function SoundControl() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.sounds = {};
        _this.channels = {};
        _this.volumeBg = 1;
        _this.volumeEffect = 1;
        _this.isNoVolume = 1;
        return _this;
    }
    SoundControl.getIns = function () {
        if (this.instance == null) {
            this.instance = new SoundControl();
        }
        return this.instance;
    };
    /**
    * 判断是否为背景声音
    * @param data 声音容器
    * @param name 声音名字
    */
    SoundControl.prototype.checkSoundIsBg = function (data, name) {
        return data[name + "-bg"];
    };
    /**
    * 声音必须是预先已经加载好的
    * @param name 声音名字
    * @param isBgSound 是不是背景声音
    */
    SoundControl.prototype.addItem = function (name, isBgSound) {
        if (isBgSound === void 0) { isBgSound = false; }
        var soundName = name;
        if (isBgSound) {
            soundName = name + "-bg";
        }
        if (!this.sounds[soundName]) {
            var sound = RES.getRes(name);
            this.sounds[soundName] = sound;
        }
    };
    /**
     * 声音必须是预先已经加载好的
     * @param name 声音名字
     * @param start 开始播放的地方，默认从头开始播放
     * @param loop 循环播放次数，默认是1次
     */
    SoundControl.prototype.play = function (name, start, loop) {
        if (start === void 0) { start = 0; }
        if (loop === void 0) { loop = 1; }
        var volume = this.volumeEffect;
        if (this.checkSoundIsBg(this.sounds, name)) {
            name = name + "-bg";
            volume = this.volumeBg;
        }
        if (this.sounds[name]) {
            var sound = this.sounds[name];
            this.channels[name] = sound.play(start, loop);
            if (this.isNoVolume == 0) {
                this.channels[name].volume = 0;
            }
            else {
                this.channels[name].volume = volume;
            }
        }
    };
    /**
     * 声音必须是预先已经加载好的
     * @param name 声音名字
     */
    SoundControl.prototype.stop = function (name) {
        if (this.checkSoundIsBg(this.channels, name)) {
            name = name + "-bg";
        }
        if (this.channels[name]) {
            var channel = this.channels[name];
            channel.stop();
        }
    };
    /**
     * 设置某个声音的音量
     *  @param name 声音名字
     *  @param volume 音量0－1
     */
    SoundControl.prototype.setVolume = function (name, volume) {
        if (this.checkSoundIsBg(this.channels, name)) {
            name = name + "-bg";
        }
        if (this.channels[name]) {
            var channel = this.channels[name];
            channel.volume = volume;
        }
    };
    /**
     * 设置所有背景声音音量
     * @param volume 音量0－1
     */
    SoundControl.prototype.setBgVolume = function (volume) {
        for (var name in this.channels) {
            if (name.split("-bg").length == 2) {
                var channel = this.channels[name];
                this.volumeBg = volume;
                if (channel.position != 0) {
                    channel.volume = volume;
                }
            }
        }
    };
    /**
     * 设置所有特效声音音量
     * @param volume 音量0－1
     */
    SoundControl.prototype.setEffectVolume = function (volume) {
        for (var name in this.channels) {
            if (name.split("-bg").length == 1) {
                var channel = this.channels[name];
                this.volumeEffect = volume;
                if (channel.position != 0) {
                    channel.volume = volume;
                }
            }
        }
    };
    /**设置是否静音
    * @param volume 是否静音0为无音1为有音
    */
    SoundControl.prototype.setIsNoVolume = function (volume) {
        this.isNoVolume = volume;
        for (var name in this.channels) {
            var channel = this.channels[name];
            if (channel.position != 0) {
                if (volume == 0) {
                    channel.volume = 0;
                }
                else {
                    if (this.checkSoundIsBg(this.sounds, name)) {
                        channel.volume = this.volumeBg;
                    }
                    else {
                        channel.volume = this.volumeEffect;
                    }
                }
            }
        }
    };
    return SoundControl;
}(egret.HashObject));
__reflect(SoundControl.prototype, "SoundControl");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var LoadingUI = (function (_super) {
    __extends(LoadingUI, _super);
    function LoadingUI() {
        var _this = _super.call(this) || this;
        _this.createView();
        return _this;
    }
    LoadingUI.prototype.createView = function () {
        this.textField = new egret.TextField();
        this.addChild(this.textField);
        this.textField.y = 300;
        this.textField.width = 480;
        this.textField.height = 100;
        this.textField.textAlign = "center";
    };
    LoadingUI.prototype.onProgress = function (current, total) {
        this.textField.text = "Loading..." + current + "/" + total;
    };
    return LoadingUI;
}(egret.Sprite));
__reflect(LoadingUI.prototype, "LoadingUI", ["RES.PromiseTaskReporter"]);
// class LoadingUI extends egret.Sprite implements RES.PromiseTaskReporter {
//     public constructor() {
//         super();
//         this.addEventListener(egret.Event.ADDED_TO_STAGE,this.addToStage,this);
//     }
//     private gameLoad:moon.GameLoad;
//     private addToStage():void {
//         this.removeEventListener(egret.Event.ADDED_TO_STAGE,this.addToStage,this);
//         //this.gameLoad = new moon.GameLoad;
//         //this.addChild(this.gameLoad);
//     }
//     public onProgress(current: number, total: number): void {
//         //this.gameLoad.update(current/total);
//         platform.progress(current/total);
//     }
// }
//子弹基础类(10 开始)
//1.生成子弹图片
//2.更换子弹的刚体
//3.负责子弹的移动，或者给力
//4.负责子弹的停止
var py2Obj;
(function (py2Obj) {
    var basicBullet = (function (_super) {
        __extends(basicBullet, _super);
        //保存外部的物理世界
        function basicBullet(world, gamePanle, romveSkins) {
            var _this = _super.call(this, world, gamePanle, romveSkins) || this;
            _this.objkind = 100;
            return _this;
        }
        basicBullet.prototype.init = function () {
            _super.prototype.init.call(this);
        };
        basicBullet.prototype.createMyRigidbody = function () {
            var world = this.m_world;
            var skin = this.createSkin("ball_png");
            var body = world.createCircleBodyShape(skin.width >> 1, p2.Body.KINEMATIC);
            body.userData.skin = skin;
            body.userData.data = this;
            body.mass = 0; //质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
            //body.gravityScale=0;
            var shape = body.shapes[0];
            //shape.collisionGroup = 2;//010与001为0，010与110为1
            shape.collisionMask = 6;
            // shape.collisionMask=2;
            // trace(shape.collisionGroup,shape.collisionMask)
            return body;
        };
        return basicBullet;
    }(py2Obj.basicObj));
    py2Obj.basicBullet = basicBullet;
    __reflect(basicBullet.prototype, "py2Obj.basicBullet");
})(py2Obj || (py2Obj = {}));
//假子弹基础类(紧紧用来演示射击)
//1.生成子弹图片
//2.更换子弹的刚体
//3.负责子弹的移动，或者给力
//4.负责子弹的停止
var py2Obj;
(function (py2Obj) {
    var fakeBullet = (function (_super) {
        __extends(fakeBullet, _super);
        function fakeBullet(world, gamePanle, romveSkins) {
            var _this = _super.call(this, world, gamePanle, romveSkins) || this;
            _this.isRun = false;
            _this.objkind = 301;
            return _this;
        }
        fakeBullet.prototype.init = function () {
            _super.prototype.init.call(this);
        };
        fakeBullet.prototype.send = function (x, y, forcex, forcey) {
            this.m_body.type = 1;
            this.isRun = true;
            this.m_body.velocity = [0, 0];
            this.m_body.damping = 0.5;
            this.setPostion(x, y);
            this.setForce(forcex, forcey);
            //this.bulletPosition_x=this.m_body.velocity[0];
            // console.log("速度"+this.m_body.velocity);
            // console.log("速度"+this.m_body.velocity[0]);
            // console.log("速度"+this.m_body.velocity[1]);
            // if(this.m_body.velocity[0]==0)
            // {
            //      console.log("速度"+this.m_body.velocity[1]);
            // }
        };
        fakeBullet.prototype.createMyRigidbody = function () {
            var world = this.m_world;
            var skin = this.createSkin("ball_png");
            var body = world.createCircleBodyShape(skin.width >> 1);
            body.userData.skin = skin;
            body.userData.data = this;
            body.mass = 0; //质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
            //this.setMaterial()
            var shape = body.shapes[0];
            shape.collisionGroup = 2; //010与001为0，010与110为1
            // shape.collisionMask=2;
            // trace(shape.collisionGroup,shape.collisionMask)
            return body;
        };
        fakeBullet.prototype.createFixedBullet = function () {
        };
        fakeBullet.prototype.runEnd = function () {
            var bullet = new py2Obj.basicBullet(this.m_world, this.m_gamePanle, this.m_removeSkins);
            bullet.init();
            bullet.setPostion(this.m_body.position[0], this.m_body.position[1]);
            this.m_gamePanle.doMaterial(bullet.getBody());
            // bullet.setForce(this.vec.x, this.vec.y);
            // this.setChildIndex(this.gun, this.numChildren - 1);
            this.isRun = false;
            this.recyle();
        };
        fakeBullet.prototype.recyle = function () {
            this.m_body.type = 2;
            this.setPostion(-100, -100);
        };
        /**
         * Body.KINEMATIC = 4;
         * Body.STATIC = 2;
         * Body.DYNAMIC = 1;
         */
        fakeBullet.prototype.getCollision = function (otherBody) {
            this.recyle();
            //	this.setPostion(this.m_body.position[0], this.m_body.position[1]);
            this.isRun = false;
        };
        return fakeBullet;
    }(py2Obj.basicObj));
    py2Obj.fakeBullet = fakeBullet;
    __reflect(fakeBullet.prototype, "py2Obj.fakeBullet");
})(py2Obj || (py2Obj = {}));
//墙体基本类基础类(10 开始)
//1.生成子弹图片
//2.更换子弹的刚体
//3.负责子弹的移动，或者给力
//4.负责子弹的停止
var py2Obj;
(function (py2Obj) {
    var basicWall = (function (_super) {
        __extends(basicWall, _super);
        //保存外部的物理世界
        function basicWall(world, gamePanle, romveSkins) {
            var _this = _super.call(this, world, gamePanle, romveSkins) || this;
            _this.objkind = 200;
            return _this;
        }
        basicWall.prototype.init = function () {
            _super.prototype.init.call(this);
        };
        basicWall.prototype.createMyRigidbody = function () {
            var world = this.m_world;
            var skin = this.createSkin("left_png");
            var body = world.createBoxBodyShape(skin.width, skin.height, p2.Body.KINEMATIC);
            body.userData.skin = skin;
            body.userData.data = this;
            body.mass = 0; //质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
            //body.gravityScale=0;
            var shape = body.shapes[0];
            //	shape.collisionGroup = 2;//010与001为0，010与110为1
            // shape.collisionMask=2;
            shape.collisionMask = 7;
            // trace(shape.collisionGroup,shape.collisionMask)
            return body;
        };
        basicWall.prototype.getCollision = function (otherBody) {
            if (otherBody.objkind >= 100 || otherBody.objkind < 200) {
                this.m_removeSkins.push(otherBody.getBody().userData.skin);
                this.m_world.removeBodys.push(otherBody);
            }
        };
        return basicWall;
    }(py2Obj.basicObj));
    py2Obj.basicWall = basicWall;
    __reflect(basicWall.prototype, "py2Obj.basicWall");
})(py2Obj || (py2Obj = {}));
//墙体基本类基础类(10 开始)
//1.生成子弹图片
//2.更换子弹的刚体
//3.负责子弹的移动，或者给力
//4.负责子弹的停止
var py2Obj;
(function (py2Obj) {
    var bottomWall = (function (_super) {
        __extends(bottomWall, _super);
        //保存外部的物理世界
        function bottomWall(world, gamePanle, romveSkins) {
            var _this = _super.call(this, world, gamePanle, romveSkins) || this;
            _this.objkind = 201;
            return _this;
        }
        bottomWall.prototype.init = function () {
            _super.prototype.init.call(this);
        };
        bottomWall.prototype.createMyRigidbody = function () {
            var world = this.m_world;
            var skin = this.createSkin("topLine_png");
            var body = world.createBoxBodyShape(skin.width, skin.height, p2.Body.KINEMATIC);
            body.userData.skin = skin;
            body.userData.data = this;
            body.mass = 0; //质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
            //body.gravityScale=0;
            var shape = body.shapes[0];
            //	shape.collisionGroup = 2;//010与001为0，010与110为1
            // shape.collisionMask=2;
            shape.collisionMask = 7;
            // trace(shape.collisionGroup,shape.collisionMask)
            return body;
        };
        bottomWall.prototype.getCollision = function (otherBody) {
            if (otherBody.objkind >= 100 || otherBody.objkind < 200) {
                this.m_removeSkins.push(otherBody.getBody().userData.skin);
                this.m_world.removeBodys.push(otherBody);
            }
        };
        return bottomWall;
    }(py2Obj.basicObj));
    py2Obj.bottomWall = bottomWall;
    __reflect(bottomWall.prototype, "py2Obj.bottomWall");
})(py2Obj || (py2Obj = {}));
var py2Obj;
(function (py2Obj) {
    var MathUtils = (function () {
        function MathUtils() {
        }
        MathUtils.getCrossPointBetweenCircleAndLine = function (cx, cy, r, stx, sty, edx, edy) {
            // 求直线
            var k = (edy - sty) / (edx - stx);
            var b = edy - k * edx;
            //列方程
            var x1, y1, x2, y2;
            var c = cx * cx + (b - cy) * (b - cy) - r * r;
            var a = (1 + k * k);
            var b1 = (2 * cx - 2 * k * (b - cy));
            var tmp = Math.sqrt(b1 * b1 - 4 * a * c);
            x1 = (b1 + tmp) / (2 * a);
            y1 = k * x1 + b;
            x2 = (b1 - tmp) / (2 * a);
            y2 = k * x2 + b;
            //判断求出的点是否在圆上
            var res = (x1 - cx) * (x1 - cx) + (y1 - cy) * (y1 - cy);
            var p = { x: 0, y: 0 };
            if (res == r * r) {
                p.x = x1;
                p.y = y1;
            }
            else {
                p.x = x2;
                p.y = y2;
            }
            return p;
        };
        MathUtils.getFootfallPoint = function (stx, sty, edx, edy, x, y) {
            var k = (edy - sty) / (edx - stx);
            var b = edy - k * edx;
            var m = x + k * y;
            var pt = { x: 0, y: 0 };
            pt.x = (m - k * b) / (k * k + 1);
            pt.y = (k * pt.x) + b;
            return pt;
        };
        MathUtils.getDistanceBetweenPointAndLine = function (x1, y1, x2, y2, x, y, body) {
            // console.log("&&&&&&&&&&&&&&&" + x1 + "," + y1 + "," + x2 + "," + y2 + "," + x + "," + y);
            var pt = MathUtils.getFootfallPoint(x1, y1, x2, y2, x, y);
            /*  var shape = new egret.Shape();
               shape.graphics.lineStyle(2, 0xff0000);
             shape.graphics.drawCircle(pt.x, pt.y, 10);
               shape.graphics.endFill();
               body.addChild(shape);
               let k= (y1-y2)/(x1-x2);
               let b = y1 -k*y1;
               /// > 0 = ax +b -y;
              */
            return Math.sqrt((x - pt.x) * (x - pt.x) + (y - pt.y) * (y - pt.y));
        };
        /// <summary>
        /// 线段与圆的交点
        /// </summary>
        /// <param name="ptStart">线段起点</param>
        /// <param name="ptEnd">线段终点</param>
        /// <param name="ptCenter">圆心坐标</param>
        /// <param name="Radius2">圆半径平方</param>
        /// <param name="ptInter1">交点1(若不存在返回65536)</param>
        /// <param name="ptInter2">交点2(若不存在返回65536)</param>
        MathUtils.LineInterCircle = function (ptStart, ptEnd, ptCenter, Radius, ptInter1, ptInter2) {
            ptInter1.x = ptInter2.x = 65536;
            ptInter2.y = ptInter2.y = 65536;
            var fDis = Math.sqrt((ptEnd.x - ptStart.x) * (ptEnd.x - ptStart.x) + (ptEnd.y - ptStart.y) * (ptEnd.y - ptStart.y));
            var d = { x: 0, y: 0 };
            d.x = (ptEnd.x - ptStart.x) / fDis;
            d.y = (ptEnd.y - ptStart.y) / fDis;
            var E = { x: 0, y: 0 };
            E.x = ptCenter.x - ptStart.x;
            E.y = ptCenter.y - ptStart.y;
            var a = E.x * d.x + E.y * d.y;
            var a2 = a * a;
            var e2 = E.x * E.x + E.y * E.y;
            var r2 = Radius * Radius;
            if ((r2 - e2 + a2) < 0) {
                return false;
            }
            else {
                var f = Math.sqrt(r2 - e2 + a2);
                var t = a - f;
                ptInter1.x = ptStart.x + t * d.x;
                ptInter1.y = ptStart.y + t * d.y;
                t = a + f;
                ptInter2.x = ptStart.x + t * d.x;
                ptInter2.y = ptStart.y + t * d.y;
                return true;
            }
        };
        MathUtils.EPS = 1e-9; //误差，小于这个就当作0
        return MathUtils;
    }());
    py2Obj.MathUtils = MathUtils;
    __reflect(MathUtils.prototype, "py2Obj.MathUtils");
})(py2Obj || (py2Obj = {}));
var DebugPlatform = (function () {
    function DebugPlatform() {
    }
    DebugPlatform.prototype.getUserInfo = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, { nickName: "username" }];
            });
        });
    };
    DebugPlatform.prototype.login = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    DebugPlatform.prototype.showShareMenu = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    DebugPlatform.prototype.share = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    DebugPlatform.prototype.init = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    return DebugPlatform;
}());
__reflect(DebugPlatform.prototype, "DebugPlatform", ["Platform"]);
if (!window.platform) {
    window.platform = new DebugPlatform();
}
// declare interface Platform {
//     getUserInfo(): Promise<any>;
//     login(): Promise<any>;
//     /**加载进度 */
//     progress(value:number): Promise<any>;
//     /**提交分数 */
//     submitScore(score:number,callback:Function,thisObject:any): Promise<any>;
//     /**获取排行榜 */
//     getRank(callback:Function,thisObject:any): Promise<any>;
//     /**获取是否可播放广告 返回boolean */
//     canPlayAd(): Promise<any>;
//     /**播放广告 */
//     playAd(callback:Function): Promise<any>;
// }
// class DebugPlatform implements Platform {
//     async getUserInfo() {
//     }
//     async login() {
//     }
//     async progress(value:number){
//     }
//     async submitScore(score:number, callback:Function, thisObject:any){
//     }
//     async getRank(callback:Function, thisObject:any){
//     }
//     async canPlayAd() {
//     }
//     async playAd(callback:Function) {
//     }
// }
// if (!window.platform) {
//     window.platform = new DebugPlatform();
// }
// declare let platform: Platform;
// declare interface Window {
//     platform: Platform
// } 
/**
     * @author vinson
     * 创建时间：2017-12-18 上午9:36:42
     * P2物理世界的模拟类
     */
var P2World = (function (_super) {
    __extends(P2World, _super);
    function P2World(x, y) {
        if (x === void 0) { x = 0; }
        if (y === void 0) { y = 0; }
        var _this = _super.call(this) || this;
        _this.colors = [10];
        _this.removeBodys = []; //需要删除的刚体
        _this.world = new p2.World({ gravity: [0, 0] });
        _this.colors[p2.Body.DYNAMIC] = 0XFF0000;
        _this.colors[p2.Body.KINEMATIC] = 0X00FF00;
        _this.colors[p2.Body.STATIC] = 0X0000FF;
        _this.addEventListener(egret.Event.ENTER_FRAME, _this.updateWorld, _this);
        _this.txtWarn = new egret.TextField;
        return _this;
    }
    Object.defineProperty(P2World.prototype, "p2World", {
        get: function () {
            return this.world;
        },
        enumerable: true,
        configurable: true
    });
    P2World.prototype.getBody = function (mass, type) {
        if (mass === void 0) { mass = 0; }
        if (type === void 0) { type = p2.Body.DYNAMIC; }
        var body = new p2.Body({ mass: mass });
        body.type = type;
        body.userData = {};
        return body;
    };
    /**创建四面墙刚体*/
    P2World.prototype.createWall = function (rect) {
        var bodys = [];
        bodys.push(this.createPlane(0, 0, 0)); //上
        bodys.push(this.createPlane(-Math.PI / 2, 0, 0)); //左
        bodys.push(this.createPlane(Math.PI, 0, rect.height)); //下
        bodys.push(this.createPlane(Math.PI / 2, rect.width, 0)); //右
        return bodys;
    };
    /**创建平面刚体*/
    P2World.prototype.createPlane = function (angle, x, y) {
        if (angle === void 0) { angle = Math.PI; }
        var shape = new p2.Plane();
        var body = this.getBody(0, p2.Body.STATIC);
        body.addShape(shape);
        body.angle = angle;
        body.position[0] = x;
        body.position[1] = y;
        this.world.addBody(body);
        return body;
    };
    /**创建圆形刚体与圆形形状 */
    P2World.prototype.createCircleBodyShape = function (radius, type) {
        if (type === void 0) { type = p2.Body.DYNAMIC; }
        var body = this.getBody(6, type);
        var shape = new p2.Circle({ radius: radius });
        body.addShape(shape);
        this.world.addBody(body);
        return body;
    };
    /***
     * 创建方形刚体与形状
     * angle=rotation*Math.PI/180
     */
    P2World.prototype.createBoxBodyShape = function (width, height, type, angle) {
        if (type === void 0) { type = p2.Body.DYNAMIC; }
        if (angle === void 0) { angle = 0; }
        var body = this.getBody(6, type);
        var shape = new p2.Box({ width: width, height: height });
        body.addShape(shape);
        body.angle = angle;
        this.world.addBody(body);
        return body;
    };
    /**创建多边形刚体与形状(值得注意的是锚点要在中间，这样就不能从[0,0]开始) */
    P2World.prototype.createConvexBodyShape = function (points, type) {
        if (type === void 0) { type = p2.Body.DYNAMIC; }
        var body = this.getBody(10, type);
        body.fromPolygon(points, { optimalDecomp: false });
        this.world.addBody(body);
        return body;
    };
    /**创建正多边形,side边数，radius为半径*/
    P2World.prototype.createPolygon = function (side, radius, type) {
        if (side === void 0) { side = 3; }
        if (radius === void 0) { radius = 30; }
        if (type === void 0) { type = p2.Body.DYNAMIC; }
        var body = this.getBody(10, type);
        var points = [];
        for (var i = 0; i < side; i++) {
            var x = Math.cos((i * (360 / side) * Math.PI / 180)) * radius;
            var y = Math.sin((i * (360 / side) * Math.PI / 180)) * radius;
            points.push([x, y]);
        }
        return this.createConvexBodyShape(points, type);
    };
    /**创建圆与方的组合体 */
    P2World.prototype.createBoxCircleBodyShape = function (width, height, type) {
        if (type === void 0) { type = p2.Body.DYNAMIC; }
        var body = this.getBody(10, type);
        body.fixedRotation = true;
        width /= 2;
        height /= 1.5;
        var shape = new p2.Box({ width: width, height: height });
        var shape2 = new p2.Circle({ radius: width / 2 });
        body.addShape(shape);
        body.addShape(shape2);
        shape.position[1] = -height;
        shape2.position[1] = -width / 2;
        this.world.addBody(body);
        return body;
    };
    /**创建刚体皮肤，如果外面设置了刚体皮肤，就不需要调用这个方法了*/
    // public drawSkin(body:p2.Body):egret.Sprite
    // {
    //     var skin:egret.Sprite=new egret.Sprite();
    //     var color:number=this.colors[body.type];
    //     skin.graphics.lineStyle(1,color,1);
    //     skin.graphics.beginFill(color,0.5);
    //     for(var i=0;i<body.shapes.length;i++){
    //         var shape:p2.Shape = body.shapes[i];
    //         var pos:egret.Point=new egret.Point(shape.position[0],shape.position[1]);
    //         if(shape instanceof p2.Box){
    //             var width:number=shape.width,height:number=shape.height;
    //             var w2:number=width/2,h2:number=height/2;
    //             skin.graphics.moveTo(pos.x,pos.y);
    //             skin.graphics.lineTo(pos.x-w2,pos.y-h2)
    //             skin.graphics.drawRect(pos.x-w2,pos.y-h2,width,height)
    //             skin.graphics.endFill();
    //         }else if(shape instanceof p2.Convex){
    //             var vertices:any[]=shape.vertices;
    //             var verLen:number=vertices.length;
    //             var vert:number[]=vertices[0];
    //             skin.graphics.moveTo(0,0);
    //             skin.graphics.lineTo(vert[0],vert[1]);
    //             for(var j=0;j<verLen;j++){
    //                 vert=vertices[j];
    //                 if(j==0) skin.graphics.moveTo(vert[0],vert[1]);
    //                 else     skin.graphics.lineTo(vert[0],vert[1]);
    //             }
    //             var vert:number[]=vertices[0];
    //             skin.graphics.lineTo(vert[0],vert[1]);
    //             skin.graphics.endFill();
    //         }else if(shape instanceof p2.Circle){
    //             var radius:number=shape.radius;
    //             skin.graphics.moveTo(pos.x,pos.y);
    //             skin.graphics.lineTo(pos.x,radius+pos.y)
    //             skin.graphics.drawCircle(pos.x,pos.y,radius);
    //             skin.graphics.endFill();
    //         }
    //     }
    //     skin.x=body.position[0];
    //     skin.y=body.position[1];
    //     body.userData.skin=skin;
    //     this.addChild(skin);
    //     return skin;
    // }
    // /**更新世界*/
    P2World.prototype.updateWorld = function (e) {
        var timeStep = 1 / 60;
        var removeBodys = this.removeBodys;
        this.world.step(timeStep);
        var bodys = this.world.bodies;
        var l = bodys.length;
        for (var i = 0; i < l; i++) {
            var body = bodys[i];
            if (body.userData && body.userData.skin) {
                var skin = body.userData.skin;
                skin.x = body.position[0];
                skin.y = body.position[1];
                skin.rotation = body.angle * 180 / Math.PI;
            }
            else {
                if (!(body.shapes[0] instanceof p2.Plane)) {
                    // this.txtWarn.x=this.txtWarn.y=200
                    // this.addChild(this.txtWarn);
                    // this.txtWarn.text="警告：有刚体没有设置皮肤"
                }
            }
        }
        for (i = 0; i < removeBodys.length; i++) {
            body = removeBodys[i];
            if (body.userData && body.userData.skin) {
                skin = body.userData.skin;
                if (skin.parent != null) {
                    //skin.parent.removeChild(skin);
                }
                body.userData = null;
            }
            this.world.removeBody(body);
        }
        if (this.loopBackFun != null) {
            this.loopBackFun();
        }
    };
    return P2World;
}(egret.DisplayObjectContainer));
__reflect(P2World.prototype, "P2World");
;window.Main = Main;